Hey all. I have a game object which has some variables like object.position = {x = 0, y = 0}
How would I go about tweening these variables? I tried GTween but couldn't get it working. It would be great to be able to tween any variable with GTween
@antix, in addition to @pie references, you may also consider using gideros MovieClip class instead of GTween, since it can do the same while being more efficient
@hgy29 I didn't notice that movieClip now has tweening embedded cool! Is it possible to set the speed of animation/tweening too? I can't find it in the reference manual. I am using gtween and tnt animator (based on mc) mostly because of this feature.
MovieClip unit is the frame, it is true that unlike GTween, if you can't set the tween speed directly in seconds, you have to multiply them by the frame rate. Having an option to have MovieClip timeline expressed in seconds would be great!
@pie - From reading that forum article it seems a class needs its own set() and get() functions for the tweening stuff to work. My entire application is in one huge main.lua file (2300 lines sofar).
@hgy29 - I don't think MovieClip is what I am looking for either. I want to tween any variables in my object, not just their x and y values and I'm not looking to animate them with MovieClip since I have written my own simple animation system in LUA.
My issue stems from the the way I am calculate where to draw objects on the screen. My code for determining if an object is visible (and should be drawn) is similar to the following code...
local objX, objY = object.position.x, object.position.y
local camX, camY = camera.position.x, camera.position.y
if(objX >= camX and objX < camX + 256and objY >= camY and objY < camY + 256)thenlocal x = objX - camX -- calculate onscreen positionlocal y = objY - camY
obj:setVisible(true)-- set visible
obj:setPosition(x, y)-- set sprite positionelse
object:setVisible(false)-- set invisibleend
If you look at the picture I attached you can see that object A is not visible to the camera and would not be drawn, but object B would. Once the code has determined its visibility it would have its sprite set to 64,64 on the screen.
So I don't want to tween the sprites x,y at all, I want to tween its position.x and position.y so it actually moves about the world, not just on the visible portion.
Maybe I need to rethink my entire approach so that tweening would work with my system. Either that or kludge some code into the tweening stuff to work with my whacky methods )
@antix I am not sure I understood what you're trying to do and what instead happens: :-B but if you don't need strange behaviours I don't think you would need to tweak GTween
Assuming that objA is on stage, to move it to "64, 64" in camera coordinate system - which is 320, 192 if objA is a child to stage - you could do:
@pie - sorry you couldn't understand what I'm trying to do. I don't think I could make it clearer
My current thinking is to have an invisible dummy sprite for every object in my world that can be tweened using global coordinates, then convert those to local coordinates and apply those to my actual object.
@antix maybe it's my fault, English is not my primary language. If you just need to update the numbers without effectively moving a sprite maybe you can just use the easing functions from easing.lua
Since you setVisible() your objects I suppose that they are somewhere on stage: so why should you bother using dummy sprites instead of using A and B directly?
@Pie - ahh okay I didn't know about the language thing
I have been rethinking and recoding..
I now have a sprite called PARENT. All game objects are children of PARENT. If I move the position of PARENT then all other objects magically move as well.
So all I need to do now is call PARENT:setPosition(-camX, -camY) and everything just works and I can now just move all game objects about using world coordinates without having to do any conversions. All I need to do is check them and set visible/invisible as required.
Thanks for helping me think my way through this :-h
MovieClip unit is the frame, it is true that unlike GTween, if you can't set the tween speed directly in seconds, you have to multiply them by the frame rate. Having an option to have MovieClip timeline expressed in seconds would be great!
Also,it would be better with these features Timescale Modifying the timeline after create the movieclip
Comments
http://appcodingeasy.com/Gideros-Mobile/Gideros-GTween-with-easing
http://giderosmobile.com/forum/discussion/980/tween-anything/p1
Is it possible to set the speed of animation/tweening too? I can't find it in the reference manual.
I am using gtween and tnt animator (based on mc) mostly because of this feature.
Thank you
Having an option to have MovieClip timeline expressed in seconds would be great!
@hgy29 - I don't think MovieClip is what I am looking for either. I want to tween any variables in my object, not just their x and y values and I'm not looking to animate them with MovieClip since I have written my own simple animation system in LUA.
My issue stems from the the way I am calculate where to draw objects on the screen. My code for determining if an object is visible (and should be drawn) is similar to the following code...
So I don't want to tween the sprites x,y at all, I want to tween its position.x and position.y so it actually moves about the world, not just on the visible portion.
Maybe I need to rethink my entire approach so that tweening would work with my system. Either that or kludge some code into the tweening stuff to work with my whacky methods )
:-B but if you don't need strange behaviours I don't think you would need to tweak GTween
Assuming that objA is on stage, to move it to "64, 64" in camera coordinate system - which is 320, 192 if objA is a child to stage - you could do:
My current thinking is to have an invisible dummy sprite for every object in my world that can be tweened using global coordinates, then convert those to local coordinates and apply those to my actual object.
If you just need to update the numbers without effectively moving a sprite maybe you can just use the easing functions from easing.lua
Since you setVisible() your objects I suppose that they are somewhere on stage: so why should you bother using dummy sprites instead of using A and B directly?
I have been rethinking and recoding..
I now have a sprite called PARENT. All game objects are children of PARENT. If I move the position of PARENT then all other objects magically move as well.
So all I need to do now is call PARENT:setPosition(-camX, -camY) and everything just works and I can now just move all game objects about using world coordinates without having to do any conversions. All I need to do is check them and set visible/invisible as required.
Thanks for helping me think my way through this :-h
Timescale
Modifying the timeline after create the movieclip