Hey guys I have a question! I am messing around with particle emitters for the first time so I am basically just trying to hook in someone’s code, that may or may not be dated. So basically I want to have a nice particle effect when the player jumps. Here is all of the respective code:
theParticle.as
package entities {
import net.flashpunk.Entity;
import net.flashpunk.graphics.Emitter;
import net.flashpunk.graphics.ParticleType;
import net.flashpunk.utils.Ease;
public class theParticle extends Entity
{
[Embed(source = '../assets/particle.png')]
private const PARTICLE:Class;
public var emitter:Emitter = new Emitter(ParticleType, 11, 11);
public function theParticle()
{
graphic = emitter;
emitter.x = emitter.y = -5;
//layer = 1;
//create dust particles
// Create a dust particle
var p:ParticleType = emitter.newType("dust", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
p.setMotion(20, 5, .2, 140, 50, .3, Ease.cubeOut);
p.setColor(0xFFFFFF, 0xFF3366, Ease.quadIn);
}
}}
thePlayer.as related variable:
public var emit:Emitter;
thePlayer.as class inside of the jump function
emit.emit("dust", x - 10 + FP.rand(20), y + 16);
thePlayer.as added function:
override public function added():void
{
emit = (FP.world.classFirst(theParticle) as theParticle).emitter;
}
The error I get when I try to jump in the game is:
“[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.”
Let me know what you guys think!
Thanks!