Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
GTween Question — Gideros Forum

GTween Question

antixantix Member
edited August 2015 in General questions
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 :)

Comments

  • hgy29hgy29 Maintainer
    @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
  • piepie Member
    @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. :)

    Thank you
  • hgy29hgy29 Maintainer
    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!
  • antixantix Member
    edited August 2015
    @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 + 256 and objY >= camY and objY < camY + 256) then
        local x = objX - camX -- calculate onscreen position
        local y = objY - camY
        obj:setVisible(true) -- set visible
        obj:setPosition(x, y) -- set sprite position
    else
        object:setVisible(false) -- set invisible
    end
    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 =))
    AGE_onscreen_processing.png
    528 x 480 - 10K
  • piepie Member
    @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:
    local endx = 320
    local endy = 192
    local tween = GTween.new(objA, 10, {x = endx, y = endy} , {delay= 0, ease = easing.inElastic } )
    This is based on your attachment, you may need to use globalToLocal / localToGlobal to translate coordinates from one system to another.
  • @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.
  • piepie Member
    @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
  • XmanXman Member
    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
Sign In or Register to comment.