2d Camera shake - add game feels to your game !

1 vote · 0 comments

Shake the camera with desired amplitude and time.

raw ·
copy
· download
--self.moaiCamera = MOAICamera2D.new() function Camera:Shake(amplitude, time) local frameTime = 0.01 local initx, inity = self.moaiCamera:getLoc() local timer = MOAITimer.new() local OnFrameUpdate = function(anim, i) time = time - frameTime local x = initx + math.random() * amplitude local y = inity + math.random() * amplitude self.moaiCamera:setLoc(x, y) if time > 0 then timer:start() else self.moaiCamera:setLoc(initx, inity) end end timer:setSpan(frameTime) timer:setListener(MOAITimer.EVENT_STOP, OnFrameUpdate) timer:setMode(MOAITimer.NORMAL) timer:start() end

Be the first to comment

Sign in with OpenID