Search code examples
haxehaxeflixel

Set certain position of FlxSprite's loadgraphic method


I have a 122 * 16 image. It has seven colors, and I use only one color per block.

But, loadGraphic() in the FlxSprite class just uses width and height.

How do I use certain position of image?

For example, if I choose 0, loadGraphic() picks up the position width, height(0 to 15, 16), choose 1, (17 ~ 31, 16)


Solution

  • Could you use an animation but change the current frame manually? Something like this:

    var sprite = new FlxSprite(100, 100);
    sprite.loadGraphic("assets/image.png", true, 122, 16);
    sprite.animation.add("my_animation", [0, 1, 2, 3, 4, 5, 6], 0, false);
    sprite.animation.play("my_animation", true, 0);
    //sprite.animation.paused = true;
    sprite.animation.frameIndex = 2; // The frame you want to display