diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 105d4194..78e08a57 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1005,6 +1005,8 @@ class MarbleWorld extends Scheduler { } } + var realDt = dt; + if (Key.isDown(Key.R)) { this.rewinding = true; } else { @@ -1085,7 +1087,10 @@ class MarbleWorld extends Scheduler { ProfilerUI.measure("updateInstances"); this.instanceManager.render(); ProfilerUI.measure("updateParticles"); - this.particleManager.update(1000 * timeState.timeSinceLoad, dt); + if (this.rewinding) { + this.particleManager.update(1000 * timeState.timeSinceLoad, -realDt); + } else + this.particleManager.update(1000 * timeState.timeSinceLoad, dt); ProfilerUI.measure("updatePlayGui"); this.playGui.update(timeState); ProfilerUI.measure("updateAudio"); diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index 3f5dcf94..cf0d2bc1 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -76,13 +76,13 @@ class Particle { var elapsed = time - this.spawnTime; var completion = Util.clamp(elapsed / this.lifeTime, 0, 1); - if (currentAge > this.lifeTime) // Again, rewind needs this + if (currentAge > this.lifeTime || currentAge < 0) // Again, rewind needs this { this.manager.removeParticle(this.data, this); return; } - if (completion == 1) { + if (completion == 1 || completion < 0) { // The particle can die this.manager.removeParticle(this.data, this); return; diff --git a/src/Settings.hx b/src/Settings.hx index 6bb59a1d..f8a6c5e6 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -62,6 +62,7 @@ typedef ControlsSettings = { var invertYAxis:Bool; var respawn:Int; var blast:Int; + var rewind:Int; } typedef TouchSettings = { @@ -143,7 +144,8 @@ class Settings { cameraSensitivity: 0.6, invertYAxis: false, respawn: Key.BACKSPACE, - blast: Key.E + blast: Key.E, + rewind: Key.R, }; public static var touchSettings:TouchSettings = { @@ -396,6 +398,9 @@ class Settings { if (controlsSettings.blast == null) { controlsSettings.blast = Key.E; } + if (controlsSettings.rewind == null) { + controlsSettings.rewind = Key.R; + } #end highscoreName = json.highscoreName; } else {