简体   繁体   中英

Corona SDK: how to slow down an object during transition

I have a game where there's enemy's that attack you and you have to try to destroy them. I have the enemy's head towards you by doing the

transition.to(OBJ, { time = 2000})

function. In the game I want to have a powerup where they can slow down the enemy. I have the enemy slow down by when transition.to() is called the time will be longer. ( for example, with the powerup unacitvated then code with be

transition.to(OBJ, {time = 2000 + slowDown } )

where slowDown = 0 , but when the user presses the powerup button slowDown = 2000 . My only problem is that pressessing the powerup button only slows down the enemy's that spawn after it is pressessed, not the current enemy's.

Is there a way that I can slow down the enemy while it is in transition?

You cannot add a new transition to an object, you need to cancel the transition, then apply the new transition with the parameters you need.

local olderTransition
local function powerUp(event)
  if olderTransition ~= nil then
    transition.cancel( olderTransition )
  end
  olderTransition = transition.to(OBJ,{time=2000 + Slowdown})
end

The idea is to use a variable for the transition, so you can cancel that transition and after that apply the new transition. If you have several enemies you probably will need an array to control what transition you cancel.

You can cancel all the transitions of an object, using the object as parameter if you need

transition.cancel( OBJ )

Check this question to see an example: Update the target coordinates while transitioning

I would use "enterFrame" event to move the enemies toward your player. Then when player picks up power up reduce enemies x and y.

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM