3 Sprites are not stamping properly
-
Hi everyone!
I'm trying to use sprite.stamp(); but I have some problems.
I have one main sprite and I wanna add sprites to behind of it and in front of it. [like burger]While just 2 sprites (for example just main and front sprites) stamp works nice, but when I stamp 3 sprites it just adding all sprites I have used before for stamping.
This is example code:
package; import flixel.FlxSprite; class { public function new() { var listspr:Map<Int,Dynamic> = [ 0 => { img:"sprite1.png" }, 1 => { img:"sprite2.png" }, 2 => { img:"sprite3.png" }, 3 => { img:"sprite4.png" }, 4 => { img:"sprite5.png" }, ]; var backSprite:FlxSprite = new FlxSprite(0, 0, "assets/images/backimage.png", false, 0, 0, true); // unique true var frontSprite:FlxSprite = new FlxSprite(0, 0, "assets/images/frontimage.png", false, 0, 0, true); // unique true for ( i in listspr ) { var obj = listspr[i]; var temp_path = obj.img; var middleimage:FlxSprite = new FlxSprite(); middleimage.loadGraphic("assets/images/" + temp_path, false, 0, 0, true); // unique true obj.img = new FlxSprite(); obj.img.loadGraphicFromSprite(backSprite); obj.img.stamp( middleimage ); obj.img.stamp( frontSprite ); add( obj.img ); } } }
How can I fix it? Thanks!
-
SOLVED
Use :
obj.img.loadGraphicFromSprite(backSprite); // WRONG BECAUSE NOT UNIQUE, JUST COPY GRAPHIC DATA
Instead of :
obj.img.loadGraphic("assets/images/backimage.png", false, 0, 0, true); // RIGHT BECAUSE OBJECT IS UNIQUE ITSELF
-
@eminfedar wouldn't just setting unique=false work in this case?:
obj.img.loadGraphic("assets/images/backimage.png", false, 0, 0, false);
-
@Brandon-R No because of Flixel's cache system, it's not working :)