ymobe/rapanui

Bitmap Text Positioning

dadooq opened this issue · 4 comments

Hi

I'm having difficulty in positioning bitmap text on a screen. I've put together a scene file that shows the problem:

aScene = {}

local sceneSplashGroup = RNGroup:new()

function aScene.onCreate()

bestText = RNFactory.createBitmapText("BEST SCORE", {
image = "kromasky.png",
charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!"%',.",
top = 55,
left = 10,
charWidth = 16,
charHeight = 16
})
bestText.x = 200;
bestText.y = 200;
sceneSplashGroup:insert(bestText)
print("bestText.y01 = "..bestText.y)
bestScore = RNFactory.createBitmapText(tostring(2309), {
image = "kromasky.png",
charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!"%',.",
top = 55,
left = 10,
charWidth = 16,
charHeight = 16
})
bestScore.x = bestText.x;
bestScore.y = bestText.y + 64;
sceneSplashGroup:insert(bestScore)
print("bestText.y02 = "..bestText.y)

thisText = RNFactory.createBitmapText("THIS SCORE", {
image = "kromasky.png",
charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!"%',.",
top = 55,
left = 10,
charWidth = 16,
charHeight = 16
})
thisText.x = bestText.x+100 --screenWidth - playBtn.originalWidth*2;
thisText.y = bestText.y;
print("bestText.y03 = "..bestText.y)
sceneSplashGroup:insert(thisText)

thisScore = RNFactory.createBitmapText(tostring(1947), {
image = "kromasky.png",
charcodes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ/0123456789:;?!"%',.",
top = 55,
left = 10,
charWidth = 16,
charHeight = 16
})
thisScore.x = thisText.x;
thisScore.y = thisText.y + 64;
print("bestText.y04 = "..bestText.y)
sceneSplashGroup:insert(thisScore)

return sceneSplashGroup
end

function aScene.onEnd()
for i = 1, table.getn(sceneSplashGroup.displayObjects), 1 do
sceneSplashGroup.displayObjects[1]:remove();
end
-- optionally remove atlas
end

return aScene

The four print statements show the following results:
bestText.y01 = 200
bestText.y02 = 119
bestText.y03 = 55
bestText.y04 = 119

If anyone can tell me what I've done wrong, I'd much appreciate it.

Hi dadooq,

this code is right , there are no mistakes.
Also the prints are Ok.

Keep in mind that "top" and "left" parameters are exactly "y" and "x" values.

So if top is 55 and you add 64 to y, result will be 119, and so on.

Hi Mattia,

Thanks for the fast reply. Not sure I made the position clear. I'm not incrementing bestText.y at any time after initialising it to 200, yet it's value appears to change.

e.g.

a=200
print(a) will show "200"
b=a+50
print(a) should still show "200" ?

this is not what is happening in my sample unless I'm seriously misreading the code - which is entirely possible at my age.

all the best

Apologies if my persistence is upsetting, but this is a real problem and the explanation given by Mattia is not correct, I think. Could you have another look at it?

hey lionK1tty

Not sure why setting a value twice would cause any problem. As I said in a previous post, the problem I'm having is equivalent to this:

a=200
print(a) will show "200"
b=a+50
print(a) should still show "200" ?

but in my code, it is showing 250. This is the value of b but not a.