I am trying to create a two player game where two players can play head to head on a tablet.
I am having trouble with aligning text for rotated text. As the number of characters is reduced, the positioning changes incorrectly (or incorrectly as to what I want to happen). Basically, I want the text to always be 20px from the edge of the screen.
So this is the code I am using:
prizeAmountPlayer2 = 10000
function test()
prizeValuePlayer2 = display.newText( prizeAmountPlayer2, 0, 0, native.systemFont, 30 )
prizeValuePlayer2:setReferencePoint( display.TopLeftReferencePoint )
prizeValuePlayer2:setTextColor( 255, 255, 0 )
prizeValuePlayer2.x = prizeValuePlayer2.contentWidth + 20
prizeValuePlayer2.y = 486
prizeValuePlayer2:rotate(180)
local timerSeconds = 20
local function updatePrize( event )
timerSeconds = timerSeconds - 1
if timerSeconds ~= 0 then
prizeAmountPlayer2 = prizeAmountPlayer2 - 500
prizeValuePlayer2.text = prizeAmountPlayer2
prizeValuePlayer2:setReferencePoint( display.TopLeftReferencePoint )
prizeValuePlayer2.x = prizeValuePlayer2.contentWidth + 20
elseif timerSeconds == 0 then
timer.cancel( questionTimer )
end
end
questionTimer = timer.performWithDelay(1000, updatePrize, 0)
end
test()
When it starts, the 10000 score is correctly placed, then when it hits 9500, it is aligned directly against the edge of the screen. When it hits 500, the last 0 is off the screen.
So I tried changing the first instance of this:
prizeValuePlayer2.x = prizeValuePlayer2.contentWidth + 20
to:
prizeValuePlayer2.x = 200
And removed these lines:
prizeValuePlayer2:setReferencePoint( display.TopLeftReferencePoint )
prizeValuePlayer2.x = prizeValuePlayer2.contentWidth + 20
from the updatePrize function, to keep it from trying to position relative to the edge and instead just at a set point.
But even still, the text still keeps shifting.
Any thoughts on how to keep that rotated text to stay 20px from the edge of the screen? [import]uid: 17827 topic_id: 21436 reply_id: 321436[/import]
[import]uid: 52491 topic_id: 21436 reply_id: 84892[/import]