Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Stuck with the for loop and animation — Gideros Forum

Stuck with the for loop and animation

rrraptorrrraptor Member
edited May 2015 in General questions
I'm new to this forum and my english not realy good, sorry.

So, i stucked with animation.
Here is the video of what i wanted: (dont know how to paste it with tag, sry :( )
I were made it by using timers. Like that:
function onAnimate(P)
   P:animate() -- updating picture of piece (P)
   P:shake(.7, 10, 10)
end
 
function tap(x,y)
   -- some code
   for ix = a, b do -- vertical line
      if Array[y][ix] ~= 0 then -- checking if cell not empty
         Array[y][ix]:switchState(false) -- switching value without updating a picture
         local aTimer = Timer.new(delay, 1) -- delay is calculated dynamically (something like that: (ix-2)*25)
         aTimer:start()
         aTimer:addEventListener(Event.TIMER_COMPLETE, onAnimate, Array[y][ix])
      else break end
   end
end
Each piece stored in the "Array" (as object ofcourse), and it have two states (on/off), also it have three methods:
-- update picture
function Piece:animate()
	if self:contains(self.frames[math.abs(self.state-2)]) then
		self:removeChild(self.frames[math.abs(self.state-2)])
	end
	if not self:contains(self.frames[self.state+1]) then
		self:addChild(self.frames[self.state+1])
	end
end
 
function Piece:setState(s, animate)
	self.state = s
	if animate then
		self:animate()
	end
	if self.arrow ~= nil then self:addChild(self.arrow) end
end
 
function Piece:switchState(animate)
	if animate == nil then animate = true end
	self:setState(math.abs(self.state-1), animate)
end
Everything works fine on my PC, but on Android device GiderosAndroidPlayer crashing if i'll be touching pieces very fast.
Any ideas how to make this effect without timers? Or how to avoid crashes on mobile devices...
And again, sorry for my bad language :)

Comments

  • rrraptorrrraptor Member
    edited May 2015
    Ok, i solved this problem...sorry to trouble you...

    Just added timer to Piece class:
    function Piece:init(...)
    	-- some code here
    	self.aTimer = Timer.new(0, 1)
    	self.aTimer:addEventListener(Event.TIMER_COMPLETE, self.aTimerComplete, self)
    end
     
    function Piece:aTimerComplete()
    	self:animate()
    	self:shake(.7, 10, 10)
    end
     
    function Piece:startAnimation(t)
    	self.aTimer:reset()
    	self.aTimer:setDelay(t)
    	self.aTimer:start()
    end
    and calling method "startAnimation" in loop.

    Likes: ar2rsawseen

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