[Resolved] Origin vs. Reference vs. X/Y

First of all, I need to say that the normally helpful docs are really confusing related to an object’s origin and reference point. My searching on the topic has pretty much only revealed more confusion and confused people. So, instead of asking for clarification on how it all works, I’ll just jump to the problem I need to solve.

Here’s what I want to do: Left-align or right-align an object to the very center of the screen.

Sure, I could just do something like this…

object.x = display.contentWidth\*0.5 + object.contentWidth\*0.5  

But since the size of the objects change and may need to move or flip left-/right-alignment, I’d like to just tell the object which alignment to be, then where to go on the screen.

My assumption is that I need to mess with object.xReference and/or object.xOrigin, but so far my effort to figure which, and with what combination, have just baffled me. [import]uid: 136105 topic_id: 24566 reply_id: 324566[/import]

We know some of the docs need working on; we’re actually in the process of setting up new sub forums for discussing specific APIs.

To your problem, I’ve always found the simplest way to be setting the reference point and positioning accordingly, eg;

[lua]obj:setReferencePoint(display.CenterRightReferencePoint)
obj.x = _W/2[/lua]

Or;

[lua]obj:setReferencePoint(display.CenterLeftReferencePoint)
obj.x = _W/2[/lua]

A working example;

[lua]_W = display.contentWidth
local toRight
local toLeft

local obj = display.newRect( 0, 0, 50, 50 )

–immediately right of center
toRight = function()
obj:setReferencePoint(display.CenterLeftReferencePoint)
obj.x = _W/2
onComplete = timer.performWithDelay(1000, toLeft, 1)
end

–immediately left of center
toLeft = function()
obj:setReferencePoint(display.CenterRightReferencePoint)
obj.x = _W/2
onComplete = timer.performWithDelay(1000, toRight, 1)
end

toRight()[/lua] [import]uid: 52491 topic_id: 24566 reply_id: 99471[/import]

Thanks so much, Peach!

Object:setReferencePoint() does exactly what I need. I really appreciate you taking the time to respond.

I didn’t mean to be harsh about that documentation, just realistic :slight_smile: Origins, reference points, coordinates, and their relationships is tricky and probably needs to be explained with lots of examples, pictures, and comparisons.
Conan. [import]uid: 136105 topic_id: 24566 reply_id: 99625[/import]

Hey Conan,

Not a problem at all.

RE the docs, you weren’t harsh - some of our docs really, REALLY need work - we know it and we don’t mind anyone saying so. It’s something we’re slowly working to improve.

Peach :slight_smile: [import]uid: 52491 topic_id: 24566 reply_id: 99716[/import]