Spritemaps in Masklists


(rostok) #1

Hello, I have a Graphiclist with couple of animated SpriteMaps. What I would like to achieve is animated Masklist. Is it possible? If so, how?


My FlashPunk 2 Beta (because of stage3D support)
(Martí Angelats i Ribera) #2

So what you really want? An animated colision box? An animated Pixelmask?


(Zachary Lewis) #3

@rostok I assume you’d like to synchronize masks with frames of animation, like having a mask that corresponds with each frame of an animation. Is this what you’re trying to achieve?


(rostok) #4

I have an entity with graphics represented by two Spritemaps and grouped into GraphicList. I would like to detect collisions based on animated pixelmasks. Not only masks should be synchronized with spritemaps as Zach suggested but also trigger collision for both of them.


(Martí Angelats i Ribera) #5

If you really need a pixelmask, this might help you. You’ll have to modify the code so you render the pixelmask instead of the Spritemap.

And to trigger both spritemaps sycronyzed you can use this:

var graphics:Vector.<Graphic> = graphiclist.children;
for (var i:int = 0; i < graphics.length; i++)
{
    (graphics[i] as Spritemap).play(/*The parameters you need*/);
}

Also, if you know how many you’ll have you can make a class wich extends Graphic or save them before add them in the pixelmask (they are not cloned so you can use that to control them).


(Zouhair Elamrani Abou Elassad) #6

… You should use the render function :

 public function Object(x:Number=0, y:Number=0) 
	{

		_maskSource = new BitmapData(width, height true, 0);
		var pixelmask:Pixelmask = new Pixelmask(_maskSource);
		

                sprFX.add("fire", [0,1,2], 13, true);
		sprFX.play("fire");
				
		mask = pixelmask;

		this.x = x;
		this.y = y;

	}
	
        override public function added():void 
	{
		super.added();
			
		graphic = new Graphiclist(sprFX);
			
	}
	
	override public function render():void 
	{
		_maskSource.fillRect(_maskSource.rect, 0);
		sprFX.render(_maskSource, new Point, new Point);
		
		super.render();
	}

(rostok) #7

Thanks guys, I solved my problem by just changing mask based on current entity state.