how to tween by a number of pixels?

Hi guys

Just wondering how I would go about Tweening my sprite by lets say 100 pixels.

I know how to tween to a certain co-ordinate (e.g: y=345), but can’t seem to figure out how to tween by a certain number of pixels :frowning:

Thank you in advance!

Hey,

You’d basically need to just add or subtract the amount from the current coords of your object.  So, something like this:

local moveByX = 10 – can be whatever you want

local moveByY = 10 – ditto

local myTween = transition.to( obj, {time=10, x=obj.x + moveByX, y=obj.y + moveByY})

Hope this helps

Rich

Thanks heaps! I knew it had to be something simple :slight_smile:

I should have thought of that!

Thanks again

No problem buddy  :slight_smile:

Rich

Actually, there is a second solution:

transition.to( obj, { delta=true, x=moveByX, y=moveByY }

Setting delta = true means that any object value you give (x,y, alpha, and so on) is an adjustment to its existing value. So you could say -10 to move left, or 10 to move right.

wow, I didn’t even know that :slight_smile: that’s an excellent solution. Thanks for sharing!

Hey,

You’d basically need to just add or subtract the amount from the current coords of your object.  So, something like this:

local moveByX = 10 – can be whatever you want

local moveByY = 10 – ditto

local myTween = transition.to( obj, {time=10, x=obj.x + moveByX, y=obj.y + moveByY})

Hope this helps

Rich

Thanks heaps! I knew it had to be something simple :slight_smile:

I should have thought of that!

Thanks again

No problem buddy  :slight_smile:

Rich

Actually, there is a second solution:

transition.to( obj, { delta=true, x=moveByX, y=moveByY }

Setting delta = true means that any object value you give (x,y, alpha, and so on) is an adjustment to its existing value. So you could say -10 to move left, or 10 to move right.

wow, I didn’t even know that :slight_smile: that’s an excellent solution. Thanks for sharing!