Screen Shake effect
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Screen Shake effect
I am trying to implement a screen shake effect that occurs each time an enemy is killed in my game, however I can't figure out for the life of me how to do so. Can anyone help me out here? Been stuck for a day or two now trying to get this working. Thanks
Re: Screen Shake effect
There is an example in the documentation of hump. If you don't want to use hump, this should work (untested, and should be adapted for use in your game):
Code: Select all
local t, shakeDuration, shakeMagnitude = 0, -1, 0
function startShake(duration, magnitude)
t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
end
function love.update(dt)
if t < shakeDuration then
t = t + dt
end
end
function love.draw()
if t < shakeDuration then
local dx = love.math.random(-shakeMagnitude, shakeMagnitude)
local dy = love.math.random(-shakeMagnitude, shakeMagnitude)
love.graphics.translate(dx, dy)
end
end
Re: Screen Shake effect
Just what I was looking for, thanks!vrld wrote:There is an example in the documentation of hump. If you don't want to use hump, this should work (untested, and should be adapted for use in your game):
Code: Select all
local t, shakeDuration, shakeMagnitude = 0, -1, 0 function startShake(duration, magnitude) t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5 end function love.update(dt) if t < shakeDuration then t = t + dt end end function love.draw() if t < shakeDuration then local dx = love.math.random(-shakeMagnitude, shakeMagnitude) local dy = love.math.random(-shakeMagnitude, shakeMagnitude) love.graphics.translate(dx, dy) end end
-
- Prole
- Posts: 2
- Joined: Fri Sep 17, 2021 6:04 am
Re: Screen Shake effect
Does this still work, good sir?
- zorg
- Party member
- Posts: 3467
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Screen Shake effect
Nothing changed in the 5 years since the last post to make it not work, a quick look at the wiki articles about the used functions would also make it obvious... also please don't necro threads in the future.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 3 guests