Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to do this, without using numerous ENTER_FRAMEs? — Gideros Forum

How to do this, without using numerous ENTER_FRAMEs?

Tom2012Tom2012 Guru
edited December 2012 in General questions
I have a character I want to walk left and right, over and over.

Is there a way to do it without attaching an enterframe loop to each one?

I've looked at gtween but it's not quite what I'm after...

Thanks

Comments

  • Thanks Plamen - just found what I needed. :-)

    I had no idea you could chain tweens in Gtween. That combined with running functions onComplete is very powerful.

    Here's the code I found...
    function someFunction()
     
    print("something")
     
    end
     
    local tween1 = GTween.new(self, 1, {x = 100}, {onComplete=someFunction})
    local tween2 = GTween.new(self, 1, {x = 400}, {autoPlay = false})
    local tween3 = GTween.new(self, 1, {alpha = .5}, {autoPlay = false})
    tween1.nextTween = tween2
    tween2.nextTween = tween3
    tween3.nextTween = tween1
     
    end
    Gideros is amazing - you learn stuff every day!
  • Tom2012Tom2012 Guru
    edited December 2012
    For anyone interested in doing the same thing, here's my class for creating an animated character that walks back and forth without using Enterframes

    (Uses TNT Animator Studio)

    The speed is pixels per second
    WormWraith = Core.class(Sprite);
     
    function WormWraith:init(scene,x,y,xDist,xSpeed)
     
    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:addToParent(anim)
    anim:playAnimation()
    self:addChild(anim)
    self.anim = anim;
     
    self:setPosition(x,y)
     
    --self:addEventListener(Event.ENTER_FRAME, onEnterFrame)
     
     
     
    -- 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 where you can change animation or do other stuff at turning point...
    function turn()
    self:setScaleX(self:getScaleX()*-1)
    end
     
     
    local tween1 = GTween.new(self, self.travelTime, {x = self.point2}, {onComplete=turn, delay=.4})
    local tween2 = GTween.new(self, self.travelTime, {x = self.point1}, {onComplete=turn, delay = .4})
    tween1.nextTween = tween2
    tween2.nextTween = tween1
     
    end
    And here's how to use it:
    local wormWraith = WormWraith.new(self,300,130,200, 50)
    stage:addChild(wormWraith)
  • @Tom2012 :) just don't forget that the fact you may not using enterFrames doesn't mean your library don't use it. You can use timers with less resolution than enterFrames for improved performance but they could go asynchronous and do time interference with display refresh and make actors move shaky.

    Likes: Tom2012

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