Location of object using newImage vs x/y properties

This line of code…

local menuGhost = display.newImage("menughost.png", 40, 188)

…and this chunk of code…

local menuGhost = display.newImage("menughost.png") menuGhost.x = 40 menuGhost.y = 188

…both appear to put the objects at the same location – except that they don’t. One is offest from the other.

It appears that one of them assumes the reference point is the upper-left and one of them assumes the reference point is the center of the object.

Except…

When I do a transition.to() and rotate each one, each rotates around its center which tells me the reference point is the same for each.

So why the difference in location when they appear on the screen?

Thanks.

Jay

[import]uid: 9440 topic_id: 6712 reply_id: 306712[/import]

This could be caused by a dozen of reasons (f.e. placed within different groups etc.). Could you provide the complete code? [import]uid: 9644 topic_id: 6712 reply_id: 23418[/import]

That is the complete code. :slight_smile:

Paste those four lines of code into a blank main.lua file and launch it in the Simulator. This is what it looks like:

Jay
[import]uid: 9440 topic_id: 6712 reply_id: 23420[/import]

it is documented explicitly though:

You can optionally specify that the image’s top-left corner be located at the coordinate (left, top); if you don’t supply both coordinates, the image will be centered about its local origin.

The local origin is at the center of the image; the reference point is initialized to this point. This means that once the image is onscreen, any further access to x or y will refer to the center of the image, not to the top/left values optionally specified in display.newImage(). You can override this behavior by specifying a different reference point for the image.

http://developer.anscamobile.com/content/display-objects
[import]uid: 6645 topic_id: 6712 reply_id: 23446[/import]

Argh! ( *swear* I read that exact page more than once and did NOT see that!

Man, I feel like such a newbie!

That said, I find it odd that the ref point would change like that – setting the coords at creation time vs right after doesn’t seem like a reason to swap how you refer to the object.

The center ref point must be some residual Flash thing because in regular graphics programming top-left has always been the standard.

Okay, I’m done here. Thanks.

Jay
[import]uid: 9440 topic_id: 6712 reply_id: 23497[/import]