Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Event trigger vs. Timer. — Gideros Forum

Event trigger vs. Timer.

Hi guys,

Nice new forum! It's been a while... :D So, still hacking away at my game but I think I'm doing something shifty. I've gotten into a bad habit of wrapping my MovieClip animations into a timer so I can do something after the animation finishes. Ew right?

I have a feeling I should be using an event trigger to tell me that the animation is finished and I can go ahead with another piece of code or function. Try as I might I'm making a mangled mess of it. Any tips? This is the bad me:
function GameScene:myWeirdnessFunction()
 
	timer1 = Timer.new(2000, 1)
 
	timer1:addEventListener(Event.TIMER, function()
 
		-- My animation.
		mc1 = MovieClip.new{
			{1, 200, PLAYER, {y = {PLAYER:getY(), height/2, "linear"}}}
		}
 
		self:addChild(mc1)
		mc1:play()
 
	end, self)
 
	timer1:start()
end
Pretty gross right? If the device is slow, things would get weird fast with this approach. Especially if the madness propagates and I start using it everywhere...

So, I'm guessing I need to do something along the lines of:
        self:addEventListener(Event.SOME_EVENT_TYPE, function() -- Where self is the game scene presumably.
 
		-- My animation.
		mc1 = MovieClip.new{
			{1, 200, PLAYER, {y = {PLAYER:getY(), height/2, "linear"}}}
		}
 
		self:addChild(mc1)
		mc1:play()
 
	end, self)
Then I hook into that somehow to fire off the next function...

I feel like I'm close, but maybe I'm way off. :) Maybe mc1:addEventListener(args)?
Tagged:

Comments

  • olegoleg Member
    edited February 2018 Accepted Answer
    function speed_move(sprite,x2,y2,speed)
            speed=speed/1000*60  --60fps
            x1, y1 = sprite:getPosition()
     
            sprite.move = MovieClip.new{
                            {1, speed, sprite, {x = {x1, x2, "linear"},y = {y1, y2, "linear"}}}  
                    }
            sprite.move:gotoAndPlay(1)
     
    		function moveout()
    			print("Event COMPLETE1") 
     
    		end
    		sprite.move:addEventListener(Event.COMPLETE, moveout)   
     
     
    end

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+4 / -0 )Share on Facebook
Sign In or Register to comment.