Created
July 16, 2017 02:38
-
-
Save DleanJeans/682f3f0236d2b118f98ad7288853f4b3 to your computer and use it in GitHub Desktop.
ScreenShake for HaxeFlixel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package systems.screen; | |
import flixel.FlxG; | |
import flixel.FlxObject; | |
import flixel.tweens.FlxEase; | |
import flixel.tweens.FlxTween; | |
import objects.Ball; | |
import objects.Wall; | |
class ScreenShake { | |
public var power:Float = 0.025; | |
private var _tween:FlxTween; | |
public function new() {} | |
public function ball(ball:Ball, object:FlxObject) { | |
shake(ball.velocity.x * power, -ball.velocity.y * power); | |
} | |
public function shake(powerX:Float, powerY:Float) { | |
if (_tween != null && !_tween.finished) | |
_tween.cancel(); | |
_tween = tweenCameraScroll(FlxG.camera.scroll.x + powerX, FlxG.camera.scroll.y + powerY).then(tweenCameraScroll(0, 0)); | |
} | |
private function tweenCameraScroll(toX:Float, toY:Float):FlxTween { | |
return FlxTween.tween(FlxG.camera.scroll, { x:toX, y:toY }, Settings.duration.screenShake); | |
} | |
private function runFor1Loop(tween:FlxTween) { | |
if (tween.executions == 2) { | |
tween.cancel(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment