Skip to content

Commit

Permalink
flxtrail separate function for update
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Sep 21, 2024
1 parent 9c6fb47 commit e7789a3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions flixel/addons/effects/FlxTrail.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont
*/
public var target(default, null):FlxSprite;

/**
* Useful if you need to have more granular control over per-sprite offsetting.
*/
public var effectOffset(default, null):FlxPoint = FlxPoint.get();

/**
* How often to update the trail.
*/
Expand Down Expand Up @@ -140,10 +145,16 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont
super.destroy();
}

override public function update(elapsed:Float):Void
{
updateTrail();
super.update(elapsed);
}

/**
* Updates positions and other values according to the delay that has been set.
*/
override public function update(elapsed:Float):Void
public function updateTrail():Void
{
// Count the frames
_counter++;
Expand All @@ -164,7 +175,7 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont
spritePosition = FlxPoint.get();
}

spritePosition.set(target.x - target.offset.x, target.y - target.offset.y);
spritePosition.set(target.x - target.offset.x - effectOffset.x, target.y - target.offset.y - effectOffset.y);
_recentPositions.unshift(spritePosition);

// Also do the same thing for the Sprites angle if rotationsEnabled
Expand Down Expand Up @@ -238,7 +249,6 @@ class FlxTrail extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCont
}
}

super.update(elapsed);
}

function cacheValue<T>(array:Array<T>, value:T)
Expand Down

0 comments on commit e7789a3

Please sign in to comment.