Combine two FlxSprites into one?

417 views
Skip to first unread message

Thomas Bernard

unread,
Nov 21, 2014, 12:39:02 PM11/21/14
to haxef...@googlegroups.com
Is there a simple solution to combine two FlxSprites into one?
I know FlxSpriteGroup can be used for this. However, I have to create an FlxSprite from the combination of two images and these images would never change their relative position/orientation/scale... thereafter. So I think it would be easier to have a single FlxSprite object, whose pixels are composed from the superposition of the pixels of my two original images (A bit like you can merge layers in Gimp to obtain a single layer) and that I could easily rotate/scale without having to worry about performing the correct change on each child of a FlxSpriteGroup.
I did not find any function to perform this in FlxSpriteUtils (a function that would be of the form: mergeSprites(backgroundSprite:FlxSprite, foregroundSprite:FlxSprite):FlxSprite ) but maybe there is some elsewhere.
There is probably a solution with creating a BitmapData from each image, combine them into a single BitmapData (Here is the tricky part as I don't know if there is an effective solution to do this without having to iterate over each pixel and compute the resulting pixel according to the alpha and colors values of each sprite (in case of partially transparent foreground Sprite, pixels of the background Sprite might be visible)) and then assign this new Bitmapdata to FlxSprite.pixels.


 

Lasent

unread,
Nov 21, 2014, 1:17:04 PM11/21/14
to

Thomas Bernard

unread,
Nov 21, 2014, 1:47:25 PM11/21/14
to haxef...@googlegroups.com
Oh perfect. Missed it (defining the Flxsprite of the stamp function as a Brush is a bit misleading though).
Thanks

On Friday, November 21, 2014 7:17:04 PM UTC+1, Lasent wrote:
http://api.haxeflixel.com/flixel/FlxSprite.html#stamp
Reply all
Reply to author
Forward
0 new messages