Reputation: 123
I have a FlxSprite
variable named mySpr
and two png files, one.png
and two.png
, inside the assets/
folder of my project.
Each png file include 4 frames and has a size of 200x200px. Can I do something like this?
mySpr.loadGraphic("assets/one.png",true,100,100);
mySpr.loadGraphic("assets/two.png",true,100,100);
mySpr.animation.add("run", [0, 1, 2, 3, 4, 5, 6, 7], 10, true);
Or is there any way to achieve a similar result?
Upvotes: 0
Views: 624
Reputation: 31
I'd advise using FlxAtlas
for that. It could look like
import flixel.graphics.atlas.FlxAtlas;
...
var atlas = new FlxAtlas("some_unique_atlas_name");
atlas.addNode("assets/one.png");
atlas.addNode("assets/two.png");
mySpr.loadGraphic(atlas.graphic,true,100,100);
mySpr.animation.add("run", [0, 1, 2, 3, 4, 5, 6, 7], 10, true);
In addition, you can use FlxAtlas
to set up animations that are presented in separate assets. You can have a look at this demo and its source code to find more details
Upvotes: 0
Reputation: 328
You can try to use the function FlxSprite.stamp()
for "appending" the second image to the side of the first (or any other location), after that is just a matter of adding another animation.
FlxSprint.stamp
function documentation: https://api.haxeflixel.com/flixel/FlxSprite.html#stamp
Upvotes: 1