So I’m trying to have a particle effect where the damage done by the player floats above the player when they do damage (think like RPG battles). The problem is, FP emitters require embedded bitmap to use as the particle image. Has anyone done something like this before with emitters, or am I going to have to create a workaround?
Using text in particle emitters?
That isn’t really what emitters are for. You’d be better using an Entity with a Spritemap for that, then having your numbers stored in the Spritemap (eg frame 0 shows 0, frame 1 shows 1 etc). If you want to display multiple numbers, either use a graphiclist or just create multiple entities (eg if you want to display 9122, create 4 entities setting the digits to ‘9’, ‘1’, ‘2’ and ‘2’ respectively).
Absolutely true, though you can’t stylise that text as much as you can with sprites!
I ve done this via an Entity and to save memory you recycle said Entity. package { import net.flashpunk.Entity; import net.flashpunk.graphics.Text;
/**
* ...
* @author Bimbamm
*/
public class E extends Entity
{
private var damageText:Text
private var speed:Number = 2; //
public function E()
{
damageText = new Text (Vars.damage + ""); // set params of text: color,size,font
graphic = text;
}
override public function update():void
{
text.alpha -= 0.02; // text is fading
y -= speed; // text is moving up
speed -= 0.05;
if (text.alpha <= 0)
{
world.recycle(this); // entity is recycled
}
super.update();
}
public function init(x:int,y:int):void
{
// update text in case damage varies
damageText.text = (Vars.damage + "");
speed = 2;
// reset speed to 2
text.alpha = 1;
// and reset alpha of the text
this.x = x;
this.y = y;
}
}
}
To store the damage i have created another Class called Vars:
public class Vars
{
// misc
public static var dmager:Number = 0;
}
In your World you call the init function of E:
you can either use
E(create(E)).init(100,100);
or (FP.world.create(E) as E).init(100,100); to display the damage. I have no idea what the difference between the two is. I would be glad if someone else could explain it. hope it helps.