1

I'm new to MOAI, mainly using it because my grad program is forcing me too. They are a fan of steep learning curves over short deadlines apparently. :)

Anyway, I have a problem where my main game loop on its own thread calls a function that triggers a 2 second animation that I also put on a separate thread. In order to allow the animation to finish before I remove the prop I tried spinlocking and I tried using easedrivers. Both make the animation work fine, but during those two seconds my main thread doesn't seem to execute at all.

The game is using Box2D so it doesn't crash during those two seconds, but all the game loop logic doesn't work during this animation. I thought the whole point of putting it on its own thread was so that it could run in conjunction with the game loop. Does anyone have any suggestions?

--inside of a another function where cheeseProp is created.

function cheeseProp:destroy ()

            animateLogoThread = MOAIThread:new ()

            --animateLogoThread = MOAICoroutine.new()

            layer:removeProp ( self )

            score = score + 10

            animateLogoThread:run ( animateLogo(self.type) )

            --animateLogo(self.type)

            timerFrames = 0

            cheeseCounter = cheeseCounter - 1

            cheeseArray[self] = nil

            self = nil

end

function animateLogo(logoNum)

local logoGfx = MOAIGfxQuad2D.new ()

logoGfx:setRect ( -100, -100, 100, 100 )

logoGfx:setTexture ( "assets/logo1.png" )





local x1, y1 = beeBody:getPosition()

local logoProp = MOAIProp2D.new()

logoProp:setDeck(logoGfx)

logoProp:setLoc ( x1, y1 )

layer:insertProp(logoProp)


logoProp:moveScl( -1, -1, 2.0)

action = logoProp:seekLoc ( x1 + 400, y1 + 400, 2.0 )

while action:isBusy () do coroutine:yield () end

-- local ease = MOAIEaseDriver.new ()


-- ease:reserveLinks ( 4 )

-- ease:setLink ( 1, logoProp, MOAIProp2D.ATTR_X_LOC, 400 )

-- ease:setLink ( 2, logoProp, MOAIProp2D.ATTR_Y_LOC, 400 )

-- ease:setLink ( 3, logoProp, MOAIProp2D.ATTR_X_SCL, -1 )

-- ease:setLink ( 4, logoProp, MOAIProp2D.ATTR_Y_SCL, -1 )

-- ease:setSpan ( 2.0 )

-- ease:start ()


-- MOAIThread.blockOnAction(ease)


layer:removeProp(logoProp)

end

As you can see by the commented out code, I've tried easedrivers with a blockOnAction, and I currently have a thread spawning and running animateLogo. Both behave exactly the same. I took out a bit of texture selecting code that shouldn't be relevant and makes the code harder to read. Like I said above, cheeseProp:destroy is called from the main game loop, it seems like my thread blocking is blocking the parent thread as well.

Thanks in advance for any help!

angryInsomniac
  • 829
  • 2
  • 13
  • 27

0 Answers0