Particle system worked so far, doesn't now -.-


(John Andersson) #1

Okay, so I’ve been using particles for a long time and usually I just forgot to add them to the world or something stupid like that, but now I know to use them.

I have some boxes that emit particles, depending on the type of box they emit a different color. But I’m using one class to handle all of the particles.

Here is the code in the game world:

(under override public function begin())

GV.BOX_EMITTER = new Box_Trail;
add(GV.BOX_EMITTER );

In GV:

public static var BOX_EMITTER = new Box_Trail;

In the class box_trail:

public class Coin_Collect_Trail extends Entity
{
	private var _emitter:Emitter;
	
	[Embed(source="../assets/graphics/particles/yellow.png")]
	private const YELLOW:Class;		
	
	[Embed(source="../assets/graphics/particles/blue.png")]
	private const BLUE:Class;		
	
	public function Coin_Collect_Trail() 
	{
		graphic = _emitter;
		layer = -3;
	}
	
	public function particleCreate(_x:Number, _y:Number, explosion:int):void
	{
		x = _x;
		y = _y;
		
		if (explosion == 1)
		{
			_emitter = new Emitter(YELLOW, 1, 1);
			_emitter.newType("1", [0, 1, 2, 3, 4, 5, 6, 7]);
			_emitter.setAlpha("1", 1, 0);
			_emitter.setMotion("1", 0, 5, 1, 15, 30, 5, Ease.quadOut);
		}
		else 
		{
			_emitter = new Emitter(RED, 1, 1);
			_emitter.newType("2", [0, 1, 2, 3, 4, 5, 6, 7]);
			_emitter.setAlpha("2", 1, 0);
			_emitter.setMotion("2", 0, 5, 1, 15, 30, .5, Ease.quadOut);
		}
		
		if (explosion == 1)
		{
			for (var amount:int = 4; amount > 0; amount --)
			{
				_emitter.emit("1", _x, _y) ;
			}
		}else if (explosion == 2)
		{
			for (var amount2:int = 4; amount2 > 0; amount2 --)
			{
				_emitter.emit("2", _x, _y) ;
			}
		}
	}
}

And finally, in the actual box entity class:

GV.BOX_EMITTER .particleCreate(x + 1, y + 248, 1);

the other box has the same code but with a “2” at the end, as I want it to output blue particles

Thank you! This is killing me


(Jacob Albano) #2

You should probably tell us what the problem is you’re having.


(John Andersson) #3

That is a good start, I guess.

Basically, the boxes don’t emit particles at all :stuck_out_tongue:


(Jean) #4

Seens that your emmiter isn’t the graphic of a Entity


(Martí Angelats i Ribera) #5

I just saw that the layer is -3 try changing that to 0 and see what happens (not sure if layer can be negative).


(John Andersson) #6

Why do you say that? :stuck_out_tongue:


(John Andersson) #7

Layers can be negative :stuck_out_tongue:


(Jean) #8

Because I already banged my head on the table only because I simply forgot to set the emmiter as a graphic of an entity.


(Martí Angelats i Ribera) #9

Could you explain a bit how are you implementing this?


(Jacob Albano) #10

Ah I think I see the problem: you assign your graphic a null value (_emitter before it’s initialized), but never set it afterwards. Move graphic = _emitter to the end of particleCreate() and you should be good to go.


(John Andersson) #11

I tried that, but it didn’t work :confused: