Implementing power-ups
Posted: Sat Apr 22, 2017 6:42 pm
I want to have power up which increments player's speed stored in player.speed, but I want to make it last only for some time - I want to do it asynchronously with callback function which would be called after defined period. What's the easiest way to do this?
Code: Select all
function Player:speedUp()
self.speed = self.speed + 1
-- this should be postponed till the end of period
setTimeout(period, function() {
self.speed = self.speed - 1
})
end