Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to blend tweens? — Gideros Forum

How to blend tweens?

MellsMells Guru
edited October 2012 in General questions
Hi,

how do you blend/mix two tweens?

I want to achieve the third effect (tween3) by mixing tween1 and tween2.
image

This is a sample code (not working).
-- ''''''''''''''''''''''''''
-- ANIMATE
-- ''''''''''''''''''''''''''
-- OBJ 1
local tween1 = GTween.new(obj1, 1, {y = obj1:getY() + 100}, {reflect = true, setLoop = true, repeatCount = 0})
 
-- OBJ 2
local tween2 = GTween.new(obj2, 4, {x = 800, y = obj2:getY() - 500}, {reflect = true, setLoop = true, repeatCount = 0})
 
-- OBJ 3
local tween3 = GTween.new(obj3, 1, {y = obj3:getY() + 100}, {reflect = true, setLoop = true, repeatCount = 0})
local tween4 = GTween.new(obj3, 4, {x = 800, y = obj3:getY() - 500}, {reflect = true, setLoop = true, repeatCount = 0})
Here is a sample file.

How would you solve this?

Thank you
twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps

Comments

  • ChangChang Member
    Accepted Answer
    I think you can do this. Separate the tween of the y coordinates into sprite and child.
    local obj3sprite = Sprite.new()
    local obj3 = drawShape(100, 900)
    obj3sprite:addChild(obj3)
    stage:addChild(obj3sprite)
     
     
    local tween3 = GTween.new(obj3, 1, {y = obj3:getY() + 100}, {reflect = true, setLoop = true, repeatCount = 0})
    local tween4 = GTween.new(obj3sprite, 4, {x = 800, y = obj3sprite:getY() - 500}, {reflect = true, setLoop = true, repeatCount = 0})
  • I'd had the same problem and ended up using a enter frame event to do the vertical bounce and a tween to do the horizontal movement, but the solution that @Chang gives is a neat way of doing it. The only thing is that I don't think tween4 needs the reflect,setloop,repeatCount parts as it it just a straight translation and not a repeated one if I understand what @Mells has drawn above correctly.
  • @Chang
    thank you for this answer.

    Your solution works well in some cases but in some others it has its limits when you don't want to change the hierarchy of your objects.

    Does GTween work with global coordinates only? - local coordinates would be the solution
    That would be great if there was a difference between globalX (current "x" value if I understand well) and localX that would be the local X for the object.

    @Petec
    True, in fact reflect, etc... was extracted from my test file (reflected for debugging).
    I tried with an enter frame event but I need the flexibility of GTween to achieve what I want (more complex than my question on this post).

    If GTween could work with local coordinates, that would be great.
    @ar2rsawseen Would you have any idea on how to achieve that?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • ar2rsawseenar2rsawseen Maintainer
    edited October 2012
    I'd agree with @Chang

    Moving a child on y axis is basically moving using local coordinates (relative to parent position) so it seems to solve problem.

    @Mells if you want local coordinates you still will need local coordinates relative to something

    Only other way I can imagine to modify one object's same property from two different tweens, in this specific case, is to use transformations. You would need to rewrite Sprite:set function to accept translation from Transformation matrix (basically using dy parameter).

    http://www.giderosmobile.com/forum/discussion/comment/5973

    And then try to tween translation and position.

    Do not know if it works because somewhere deep it should be the same as changing position coordinates.
  • Ok another specific idea, if amplitude of bouncing on y axis is not greater than height of object and object is Bitmap, then you could rewrite Sprite:set function to accept anchorPoints and try to animate that :)
  • Well, in that case you may try the method suggested by @ar2rsawseen. Or create a loop function to create the tweens in arrays with some maths, in order to create tweens like below:
    local obj3 = drawShape(100, 400)
    stage:addChild(obj3)
     
    local desiredHeight = 500
     
    local tweenUp4 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight}, {autoPlay = false})
    local tweenDown3 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.75 + 100}, {autoPlay = false, nextTween = tweenUp4})
    local tweenUp3 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.75}, {autoPlay = false, nextTween = tweenDown3})
    local tweenDown2 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.5 + 100}, {autoPlay = false, nextTween = tweenUp3})
    local tweenUp2 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.5}, {autoPlay = false, nextTween = tweenDown2})
    local tweenDown1 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.25 + 100}, {autoPlay = false, nextTween = tweenUp2})
    local tweenUp1 = GTween.new(obj3, 0.5, {y = obj3:getY() - desiredHeight*0.25}, {nextTween = tweenDown1})
     
     
    local tweenX = GTween.new(obj3, 3.5, {x = 800}, {repeatCount = 1})
    :) some brute forces here, could be easier when you figure out a nice loop function to create them.
Sign In or Register to comment.