Transition Bug - reference change causes object to jump

Changing the xReference and yReference of an object BEFORE a transition.to makes the object jump. What seems to happen is the obj.x, obj.y of the object is changed when the Reference point changes.

Then, when I call the transition.to to go to a new x,y, the obj jumps to the changed obj.x, obj.y, then transitions to the correct x,y offset by the correct, new xReference, yReference.

Who cares?

Well, what if you have an object which you position when it was aligned “TopLeft”. Then, you change the alignment of an object to “Center” and then transition that object to a the center of the screen? It’s great…the obj moves to the center of the screen.

Now, how to get it back? Set the alignment to “TopLeft” again, transition to the old coordinates, and Voila! the damned thing jumps like a rat on a hotplate.

Help!

[import]uid: 37366 topic_id: 14725 reply_id: 314725[/import]

What about leaving the reference point in the top left, and use the width and height of the object in question in the transition.to?

Try this out. For the image I’m loading, dig it out of any of the Corona sample code that ships with Corona. Copy the “Icon-72.png” into the folder and you should be good to go.

[lua]display.setStatusBar( display.HiddenStatusBar );
local _W, _H = display.contentWidth, display.contentHeight;
local back = display.newRect( 0, 0, _W, _H );
back:setFillColor ( 100, 100, 100 )
local icon = display.newImage(“Icon-72.png”);
icon:setReferencePoint(display.TopLeftReferencePoint);
icon.x = 0; icon.y = 0;

transition.to ( icon, {x = (_W*0.5) - (icon.contentWidth*0.5), y = (_H*0.5) - (icon.contentHeight*0.5), time = 1500, delay = 1500} );
transition.to ( icon, {x = 0, y = 0, time = 1500, delay = 5000} );[/lua]

I tested on all the available hardware in the simulator.

Let me know if that helps you out. [import]uid: 5317 topic_id: 14725 reply_id: 54495[/import]

Thanks for that tip. I’m trying to allow my XML code to allow an object to be transitioned from x2,y2 to x2,y2, with any alignment (i.e. TopLeft, Center, etc.).

I can definitely code the alignments by hand, but I was hoping Corona would handle that for me.

This is a bug, right? Transition.to should start an object at its current x,y, not at the x,y that changes because the xReference, yReference has changed. [import]uid: 37366 topic_id: 14725 reply_id: 54605[/import]


This is a bug, right? Transition.to should start an object at its current x,y, not at the x,y that changes because the xReference, yReference has changed.

I’m not sure it’s a bug. Most engines don’t allow you to change the reference point at runtime, since it affects so many other things.

Now, I think with careful testing, you can figure out the amount of shift in the object based on changing the reference points. For example, an object with TopLeftReferencePoint, set at 0,0 would have the top left corner at 0,0. If you switch that to a CenterReferencePoint, and don’t change the x, y position, I would assume that the object will jump to the center of the object at 0,0. Given that, you can calculate the offset needed to compensate for the offset. Switch the reference point and adjust the position accordingly. If you use the object.contentWidth and object.contentHeight in your calculations, the functions should be reusable regardless of the image size.

Just my thoughts… [import]uid: 5317 topic_id: 14725 reply_id: 54657[/import]