mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-28 07:22:21 -08:00
Smoother Screenshake Reduction (#8310)
* Smoother Screenshake Reduction Screen shake will now always reach 0 no matter the intensity or duration without being cut off early. * Keep the max reduction rate
This commit is contained in:
parent
9aa45b2a7c
commit
552d6a2e9f
1 changed files with 6 additions and 3 deletions
|
|
@ -72,6 +72,8 @@ public class Renderer implements ApplicationListener{
|
|||
landPTimer,
|
||||
//intensity for screen shake
|
||||
shakeIntensity,
|
||||
//reduction rate of screen shake
|
||||
shakeReduction,
|
||||
//current duration of screen shake
|
||||
shakeTime;
|
||||
//for landTime > 0: if true, core is currently *launching*, otherwise landing.
|
||||
|
|
@ -83,14 +85,15 @@ public class Renderer implements ApplicationListener{
|
|||
Shaders.init();
|
||||
|
||||
Events.on(ResetEvent.class, e -> {
|
||||
shakeTime = shakeIntensity = 0f;
|
||||
shakeTime = shakeIntensity = shakeReduction = 0f;
|
||||
camShakeOffset.setZero();
|
||||
});
|
||||
}
|
||||
|
||||
public void shake(float intensity, float duration){
|
||||
shakeIntensity = Math.max(shakeIntensity, intensity);
|
||||
shakeIntensity = Math.max(shakeIntensity, Mathf.clamp(intensity, 0, 100));
|
||||
shakeTime = Math.max(shakeTime, duration);
|
||||
shakeReduction = Math.max(shakeReduction, shakeIntensity / shakeTime);
|
||||
}
|
||||
|
||||
public void addEnvRenderer(int mask, Runnable render){
|
||||
|
|
@ -210,7 +213,7 @@ public class Renderer implements ApplicationListener{
|
|||
float intensity = shakeIntensity * (settings.getInt("screenshake", 4) / 4f) * 0.75f;
|
||||
camShakeOffset.setToRandomDirection().scl(Mathf.random(intensity));
|
||||
camera.position.add(camShakeOffset);
|
||||
shakeIntensity -= 0.25f * Time.delta;
|
||||
shakeIntensity -= shakeReduction * Time.delta;
|
||||
shakeTime -= Time.delta;
|
||||
shakeIntensity = Mathf.clamp(shakeIntensity, 0f, 100f);
|
||||
}else{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue