Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Simultaneously tweening and sprite animation — Gideros Forum

Simultaneously tweening and sprite animation

BigbooteyBigbootey Member
edited June 2013 in General questions
Is it possible to execute a tween (to move a sprite) and in the same time having the sprite animated (with multiple bitmap) ?

Thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Yes and you'll need to use MovieClip for that.
    It both provides frame animation and tweening capabilities:
    http://docs.giderosmobile.com/reference/gideros/MovieClip#MovieClip
  • How can I specify the frame animation in my current sprite displacement :

    mv = MovieClip.new({
    {1, 50, mySprite,
    {x = {xo, xi, "outBack"}, y = {yo, yi, "outBack"}}},
    {50, 80, mySprite,
    {x = {xi, xt, "linear"}, y = {yi, yt, "outBounce"}}}
    })

    Where xo,yo = original position, xi,yi = intermediate position and xt,yt = target positon.

    The result is something like that :

    ***(i)
    ** *
    * *
    * *
    * *
    *(o) * (t)

    The solution for the movement is very interesting so I've just 1 or 2 positions to compute, the tweening makes the other calculations for a smooth movement.

    I expected to keep the tween simple and just animate the moving sprite.

    I've tried to define mySprite as a movieClip (or 2 in this case) with frame animation :

    mySprite = MovieClip.new{
    {1, 5, jump[1]},
    {6, 10, jump[2]},
    ...
    {71, 75, jump[15]},
    {76, 80, jump[16]}
    }

    but it seems not to work.

    Do I have to cut the whole movement and change the bitmap at each keyframe (~20) ?
    That's no more so easy to compute.

    Thank's for your answer.
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Well, another option is to try GTween library, so you could simple animate MovieClip and tween it separately.
    http://giderosmobile.com/tools/gtween

    Dislikes: anneMurielle

    +1 -1 (+0 / -1 )Share on Facebook
  • Thank's

    You mean GTween can tween a movieclip ! Cool ! :)
    I'll try it this weekend.
  • Tom2012Tom2012 Guru
    edited June 2013
    Hello

    I use Gtween and TNT Animator with Gideros to do this.

    Here's my class that I used to do animation and tweens. (It uses continuous tweens and fires some functions to change animation and key points...) Let me know if any of this sounds like gibberish or there's anything I can do to help. :D

    http://www.tntparticlesengine.com
    AcidFish = Core.class(Sprite)
     
    function AcidFish:init(scene,x,y,yDist,startDelay,delayBetween)
     
    	self.scene = scene
    	self.startDelay = startDelay
    	self.delayBetween = delayBetween
    	self.yDist = yDist
    	self.timeTaken = yDist / 300
     
    	local anim = CTNTAnimator.new(self.scene.atlas2AnimLoader)
    	anim:setAnimation("ACID_FISH_FLYING")
    	anim:setAnimAnchorPoint(.5,.5)
    	anim:addToParent(anim)
    	anim:playAnimation()
    	self:addChild(anim)
    	self.anim = anim
     
    	self.name = "fish"
     
    	-- Add tweens
     
     
    	Timer.delayedCall(self.startDelay, function() 
     
    		self.upTween = GTween.new(self, self.timeTaken, {y = y-self.yDist},{delay=self.delayBetween,ease = easing.outQuadratic})
    		self.upTween:addEventListener("complete", self.closeMouth, self)
    		self.upTween.dispatchEvents = true
     
    		local downTween = GTween.new(self, self.timeTaken, {y = y},{delay=.3,ease = easing.inQuadratic,autoPlay=false})
     
    		downTween:addEventListener("complete", self.openMouth,self)
    		downTween.dispatchEvents = true
     
    		self.upTween.nextTween = downTween
    		downTween.nextTween = self.upTween
     
    	end)
     
     
     
    	self.scene = scene
    	self.xSpeed = xSpeed
    	self.direction = direction
     
    	-- Hitbox stuff
     
    	self.damage = 2 -- how much hurts hero
    	self.hitBoxShape = "box"
    	self.hitBoxX = 0
    	self.hitBoxY = 0
    	self.hitBoxW = 36
    	self.hitBoxH = 57
     
    	table.insert(self.scene.enemies, self) -- detect collisions
     
     
     
    end
     
     
     
    function AcidFish:openMouth()
    	self.anim:setAnimation("ACID_FISH_FLYING")
    	self.anim:playAnimation()
    end
     
    function AcidFish:closeMouth()
    	self.anim:setAnimation("ACID_FISH_BITING")
    	Timer.delayedCall(200, self.falling, self)
    end
     
    function AcidFish:falling()
    	self.anim:setAnimation("ACID_FISH_CLOSED")
    	self.anim:playAnimation()
    end
  • I've tried with GTween, but in fact it's working perfectly with a MovieClip.
    Not enough tested in my first solution.

    @Tom
    I'll try your solution, which seems better for more complex animations. :)>- :-?
Sign In or Register to comment.