Skip to content

Commit

Permalink
add pixelPerfectShake (HaxeFlixel#2841)
Browse files Browse the repository at this point in the history
* add pixelPerfectShake

* move PPshake

* default ppshake to pprender

* remove old code

* spacing
  • Loading branch information
Geokureli authored Jun 15, 2023
1 parent ffa614d commit 47c9171
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ class FlxCamera extends FlxBasic
* WARNING: setting this to `false` on blitting targets is very expensive.
*/
public var pixelPerfectRender:Bool;

/**
* If true, screen shake will be rounded to game pixels. If null, pixelPerfectRender is used.
* @since 5.4.0
*/
public var pixelPerfectShake:Null<Bool> = null;

/**
* How wide the camera display is, in game pixels.
Expand Down Expand Up @@ -1315,13 +1321,23 @@ class FlxCamera extends FlxBasic
}
else
{
final pixelPerfect = pixelPerfectShake == null ? pixelPerfectRender : pixelPerfectShake;
if (_fxShakeAxes.x)
{
flashSprite.x += FlxG.random.float(-_fxShakeIntensity * width, _fxShakeIntensity * width) * zoom * FlxG.scaleMode.scale.x;
var shakePixels = FlxG.random.float(-1, 1) * _fxShakeIntensity * width;
if (pixelPerfect)
shakePixels = Math.round(shakePixels);

flashSprite.x += shakePixels * zoom * FlxG.scaleMode.scale.x;
}

if (_fxShakeAxes.y)
{
flashSprite.y += FlxG.random.float(-_fxShakeIntensity * height, _fxShakeIntensity * height) * zoom * FlxG.scaleMode.scale.y;
var shakePixels = FlxG.random.float(-1, 1) * _fxShakeIntensity * height;
if (pixelPerfect)
shakePixels = Math.round(shakePixels);

flashSprite.y += shakePixels * zoom * FlxG.scaleMode.scale.y;
}
}
}
Expand Down

0 comments on commit 47c9171

Please sign in to comment.