Common issue, but can I find 'that Turorial', can I ****!

Dead simple problem and I know it’s been answered before because I’ve stumbled upon the ‘script’ that deals with it… Damn me to hell for not pressing cmd+D when I saw it.

It’s a question of scoring… I’ve used "Score = display.newText( “Score: " … scoreTotal, 0, 0, native.systemFont, 28 )” - as a simple scoring system (to start with, like everyone does). The problem is the reference point. When I “Score = Score + 500”, my score ‘moves’ as if it’s centrally justified. I’ve tried including setReferencePoint into different parts of the code and it’s pertinent event calls/handlers but I can’t seem to get the Score to stop justifying itself when it’s updated.

If someone knows where ‘that tutorial’ is, that shows you how to avoid this issue, a pointer would be nice.

NOTE FOR THE CORONA TEAM:

Did you know… If you use “display.newEmbossedText” with the above ‘simple scoring system’, that it doesn’t update at all? - Strange but true.

Thanks by the way, to anyone who can help with my issue.

Mark [import]uid: 176868 topic_id: 35585 reply_id: 335585[/import]

  1. Use < code > < / code > (without the spaces) to encapsulate your code when posting here; makes it look all nice and understandable :slight_smile:

  2. Basically all display objects use reference points like this:
    a. While initialized (that is, within the brackets) it’s TopLeft
    b. Afterwards, it’s Center

This is not exactly the most obvious or ideal setup, but here’s how you work with it:

i. Always :setReferencePoint before setting x/y. (Any typos in the reference point and it won’t work.)

-- Correct order local object = display.newText("Hi", 0, 0, native.systemFont, 28) object:setReferencePoint(display.TopLeftReferencePoint) -- all words in the point are capitalized object.x = 32 object.y = 48

ii. Consider setting your x/y outside of the initialization. (As in the above code). A lot of times people do this because they need a difference reference point or want to use a bunch of math (which doesn’t look great between two commas)

iii. If you want, you can code it to it for you, of course. It’s a bit of hassle, but if you’re making a lot of code it could help.

[code] – :setText()
local function setText(self, string)
self:setReferencePoint(display.TopLeftReferencePoint)
self.oldX = self.x; self.oldY = self.y

self.text = string
self:setReferencePoint(display.TopLeftReferencePoint)
self.x = self.oldX; self.y = self.oldY
end[/code]

[code] – How to use
– Method 1
object.setText = setText – this is how you attach the function
object:setText( “wowzers” )

– Method 2 (only works if setText is in scope)
setText(object, “wowzers” )[/code]

  1. AFAIK from past experience newEmbossedText() works the same way, only the method of changing the text is different because technically there are two text objects (the text and the shadow text behind it). This function can’t use .text to change text, so it uses :setText - not the same thing as mine, but it’s own version. You could still use the same function approach, but you would have to change the name of the custom function as well as change the .text line to :setText… [import]uid: 41884 topic_id: 35585 reply_id: 141407[/import]
  1. Use < code > < / code > (without the spaces) to encapsulate your code when posting here; makes it look all nice and understandable :slight_smile:

  2. Basically all display objects use reference points like this:
    a. While initialized (that is, within the brackets) it’s TopLeft
    b. Afterwards, it’s Center

This is not exactly the most obvious or ideal setup, but here’s how you work with it:

i. Always :setReferencePoint before setting x/y. (Any typos in the reference point and it won’t work.)

-- Correct order local object = display.newText("Hi", 0, 0, native.systemFont, 28) object:setReferencePoint(display.TopLeftReferencePoint) -- all words in the point are capitalized object.x = 32 object.y = 48

ii. Consider setting your x/y outside of the initialization. (As in the above code). A lot of times people do this because they need a difference reference point or want to use a bunch of math (which doesn’t look great between two commas)

iii. If you want, you can code it to it for you, of course. It’s a bit of hassle, but if you’re making a lot of code it could help.

[code] – :setText()
local function setText(self, string)
self:setReferencePoint(display.TopLeftReferencePoint)
self.oldX = self.x; self.oldY = self.y

self.text = string
self:setReferencePoint(display.TopLeftReferencePoint)
self.x = self.oldX; self.y = self.oldY
end[/code]

[code] – How to use
– Method 1
object.setText = setText – this is how you attach the function
object:setText( “wowzers” )

– Method 2 (only works if setText is in scope)
setText(object, “wowzers” )[/code]

  1. AFAIK from past experience newEmbossedText() works the same way, only the method of changing the text is different because technically there are two text objects (the text and the shadow text behind it). This function can’t use .text to change text, so it uses :setText - not the same thing as mine, but it’s own version. You could still use the same function approach, but you would have to change the name of the custom function as well as change the .text line to :setText… [import]uid: 41884 topic_id: 35585 reply_id: 141407[/import]