Fxtrail problem with sprites with several animations

104 views
Skip to first unread message

Tembac

unread,
May 12, 2014, 8:23:33 PM5/12/14
to haxef...@googlegroups.com
Hello everyone,

I'm not sure if this is a bug or something I'm missing. I'm making a trail of an sprite that has several animations. The trail works fine for the first animation but when I play the second one the trail is still the same image as the first animation.

Here is my code or you can download the project here: https://dl.dropboxusercontent.com/u/24695185/TestAnimatedTrail.rar

class MenuState extends FlxState
{
public var player:FlxSprite;
public var trail:FlxTrail;
/**
* Function that is called up when to state is created to set it up. 
*/
override public function create():Void
{
super.create();
player = new FlxSprite(FlxG.width * .5, FlxG.height * .5);
player.loadGraphic("assets/images/character.png", true);
player.animation.add("anim01", [0]);
player.animation.add("anim02", [1]);
add(player);
FlxTween.circularMotion(player, (FlxG.width * 0.5) - (player.width / 2), (FlxG.height * 0.5) - (player.height / 2), FlxG.width*.35, 359, true, 5, true, { type:FlxTween.PINGPONG } );
trail = new FlxTrail(player, null, 100, 3, 1, 0);
trail.setAll("width", player.width);
trail.setAll("height", player.height);
trail.setAll("offset", new FlxPoint(0, 0));
add(trail);
}
/**
* Function that is called when this state is destroyed - you might want to 
* consider setting all objects this state uses to null to help garbage collection.
*/
override public function destroy():Void
{
super.destroy();
}

/**
* Function that is called once every frame.
*/
override public function update():Void
{
super.update();
{
{
}
else
{
}
}
}
}


Gama11

unread,
May 13, 2014, 4:31:29 AM5/13/14
to haxef...@googlegroups.com
I'm not sure FlxTrail supports animations... Have you tried using a FlxTrailArea instead? It should be more performant as well.

Tembac

unread,
May 21, 2014, 2:41:03 AM5/21/14
to haxef...@googlegroups.com
I tried FlxTrailArea now and it seems to be slower. On my nexus one with the regular Flxtrail I got 30fps and with FlxTrailArea I get 10fps.

I have only one sprite in the Trail Area.

Tembac

unread,
May 27, 2014, 1:39:25 AM5/27/14
to haxef...@googlegroups.com
Fixed the issue with FlxTrail and animations. I think this solution works because I tested on my phone and the framerate is back in 30fps.

I'm learning how to use Github so I don't know how to commit the change but I'll paste it here in case someone wants to do it.

Line 81 added:
/**
*  Stores the sprites recent animations.
*/
private var _recentAnimations:Array<FlxAnimation>;

in new()
_recentAnimations = new Array<FlxAnimation>();

in destroy()
_recentAnimations = null;

in update:
// Again the same thing for Sprites frames if framesEnabled
if (framesEnabled && _image == null) 
{
var spriteAnimation:FlxAnimation = sprite.animation.curAnim;
_recentAnimations.unshift(spriteAnimation);
if (_recentAnimations.length > _trailLength)
{
_recentAnimations.pop();
}
var spriteFrame:Int = sprite.animation.frameIndex;
_recentFrames.unshift(spriteFrame);
if (_recentFrames.length > _trailLength) 
{
_recentFrames.pop();
}
var spriteFacing:Int = sprite.facing;
_recentFacings.unshift(spriteFacing);
if (_recentFacings.length > _trailLength) 
{
_recentFacings.pop();
}
}


Saludos,

SruloArt

unread,
May 27, 2014, 2:18:15 AM5/27/14
to haxef...@googlegroups.com
Tembac, do try to open this as an issue on Github, even just as a copy-paste for starters, these lines may be forgotten sooner than you might think...

Tembac

unread,
May 27, 2014, 4:05:16 PM5/27/14
to haxef...@googlegroups.com
Thanks!

Did the issue. I hope this is fixed in the next flixel version.
Reply all
Reply to author
Forward
0 new messages