Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Problems pausing chained tweens — Gideros Forum

Problems pausing chained tweens

Tom2012Tom2012 Guru
edited December 2012 in General questions
I like chaining tweens but pausing them is problematic.

I'm getting odd things happening, such as the character jumping and moving backwards etc...

Here's the code:
self.tween1 = GTween.new(self, self.travelTime, {x = self.point2}, {onComplete=turn, delay=.1})
 
self.tween2 = GTween.new(self, self.travelTime, {x = self.point1}, {autoPlay = false, onComplete=turn, delay = .1})
 
self.tween1.nextTween = self.tween2
self.tween2.nextTween = self.tween1
And here's the bit where I'm pausing...
	self.health = self.health - 1
	self.invincible = true
 
	if (self.tween1:isPaused() == false) then
		self.tween1:setPaused(true)
	end
 
	if (self.tween2:isPaused() == false) then
		self.tween2:setPaused(true)
	end
 
 
	self.anim:setAnimation("WORM_WRAITH_HIT")
	Timer.delayedCall(400, function()
		self.invincible = false
 
 
	if (self.tween1:isPaused() == true) then
		self.tween1:setPaused(false)
	end
 
	if (self.tween2:isPaused() == true) then
		self.tween2:setPaused(false)
	end
I'll post the entire code in the next post...

Comments

  • Tom2012Tom2012 Guru
    edited December 2012
    WormWraith = Core.class(Sprite);
     
    function WormWraith:init(scene,tileX,tileY,xDist,xSpeed)
     
    -- work out the x and y from tile reference
     
    tileX = tileX + 1
    tileY = tileY + 1
     
    self.xPos = (tileX * 50) - 25
    self.yPos = (tileY * 50) - 25
    self.health = 3
     
    self.scene = scene
     
     
    local animLoader = CTNTAnimatorLoader.new()
    animLoader:loadAnimations("Animations/Atlas 2 Animations.tan", self.scene.atlas2, true)
    local anim = CTNTAnimator.new(animLoader)
    anim:setAnimation("WORM_WRAITH_WALK")
    anim:setAnimAnchorPoint(.5,.5)
    anim:addToParent(anim)
    anim:playAnimation()
    self:addChild(anim)
    self.anim = anim;
     
    self:setPosition(self.xPos,self.yPos)
     
    self.facing = "left"
    table.insert(self.scene.enemies, self)
     
     
     
    -- add transition
     
    self.animProperties = {}
     
    self.animProperties.repeatCount = 1
    self.animProperties.dispatchEvents = true 
     
     
     
    -- first work out the x positions
     
    self.point1 = self:getX()
    self.point2 = self.point1 - xDist;
     
    self.travelTime = xDist / xSpeed
     
    function turn()
     
    	anim:setAnimation("WORM_WRAITH_TURN")
     
     
    		Timer.delayedCall(100, function()
     
    			if(not(self.dead)) then
    				anim:setAnimation("WORM_WRAITH_WALK")
    			end
     
    	if(self.facing=="left") then
     
    		self:setScaleX(-1)
    		self.facing = "right"
     
    	else
     
    		self:setScaleX(1)
    		self.facing = "left"
     
    	end
     
     
    	end)
     
     
    end
     
    self.invincible = true
    Timer.delayedCall(1000, function() self.invincible = false end)
     
     
    self.tween1 = GTween.new(self, self.travelTime, {x = self.point2}, {onComplete=turn, delay=.1})
     
    self.tween2 = GTween.new(self, self.travelTime, {x = self.point1}, {autoPlay = false, onComplete=turn, delay = .1})
     
    self.tween1.nextTween = self.tween2
    self.tween2.nextTween = self.tween1
     
    end
     
     
     
     
    function WormWraith:reduceHealth(index)
     
    if(not(self.invincible)) then
     
    	self.health = self.health - 1
    	self.invincible = true
     
    	if (self.tween1:isPaused() == false) then
    		self.tween1:setPaused(true)
    	end
     
    	if (self.tween2:isPaused() == false) then
    		self.tween2:setPaused(true)
    	end
     
     
    	self.anim:setAnimation("WORM_WRAITH_HIT")
    	Timer.delayedCall(400, function()
    		self.invincible = false
     
     
    	if (self.tween1:isPaused() == true) then
    		self.tween1:setPaused(false)
    	end
     
    	if (self.tween2:isPaused() == true) then
    		self.tween2:setPaused(false)
    	end
     
     
    		if(not(self.dead)) then
    			self.anim:setAnimation("WORM_WRAITH_WALK")
    		end
     
    	end)
     
    	-- I have died
     
    	if(self.health<=0) then
     
    		self.tween1:setPaused(true)
    		self.tween2:setPaused(true)
    		self.dead = true
    		table.remove(self.scene.enemies, index)
    		self.anim:setAnimation("WORM_WRAITH_DIE")
     
    		Timer.delayedCall(1000, function()
    			local tween = GTween.new(self, .3, {alpha=0})
    		end)
     
    		Timer.delayedCall(1400, function()
    			self.scene.enemyLayer:removeChild(self)
    		end)
     
    	end
     
    end
     
    end
  • Tom2012Tom2012 Guru
    edited December 2012
    I have figured this out...

    The problem is you can't pause all tweens in the chain. You have to find out which tween is the current one and only pause that.

    In my case I used this in the function that runs after each tween:
    if(self.currentTween==1) then
    	self.currentTween = 2
    else
    	self.currentTween = 1
    end
    In conjunction with...
    	if(self.currentTween==1) then
    		self.tween1:setPaused(true)
    	else
    		self.tween2:setPaused(true)
    	end
    To only pause the current tween...

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.