[SOLVED] Falling Snow With Emitters


(Zouhair Elamrani Abou Elassad) #1

I’m trying to create a falling snow that moves with the camera using emitters this what i did so for :

   override public function begin():void 
	{
		
		// Create emitter's graphic
		var bd:BitmapData = new BitmapData(6, 3, true, 0);
		bd.setPixel32(1, 1, 0xFFFFFFFF);
		bd.fillRect(new Rectangle(3, 0, 3, 3), 0xFFFFFFFF);
		
		// Create emitter
		_emitter = new Emitter(bd, 3, 3);
		_emitter.relative = false;
		
		// Set the properties for the snow
		_emitter.newType(SNOW, [0]);
		_emitter.setMotion(SNOW, 40, 5, .2, 200, 1000, .3, Ease.cubeOut);
		
		addGraphic(_emitter);
		
		super.begin();
	}
	
	public function emit(type:String, x:int, y:int, size:uint=0):void
	{
		_emitter.emit(type, x, y);		
	}
	
	override public function update():void 
	{
		
		var interval:int = 40;
		for (var o:int = 0; o < FP.width; o += interval)
		{
			emit(SNOW, o + FP.camera.x, -10);
		}
		
		_emitter.y += 150 * FP.elapsed;
		
		super.update();
	}

I get multiple particles but they’re not falling the way they supposed to, and is there a way to let them disappear before they arrive to the bottom of the screen !


(Mike Evmm) #2

if it’s moving with the camera for “checking whether out of screen” you’ll want to check (for instance)

x > FP.camera.x + FP.width;

instead of

x>FP.width;

Misread, sorry.


(Ben Pettengill) #3

My first thought looking at your code: What is Ease,.cubeOut for? Snow falls at a linear rate. It doesn’t slow down before it lands, which is what that easer function would do. Try leaving that parameter blank.

As for making them disappear sooner, you need to adjust the duration and distance. With particle effects, sometimes you just need to experiment to make it look right.


(Zouhair Elamrani Abou Elassad) #4

I see, thank’s a lot for the explanations, i got it done ^^


(Zouhair Elamrani Abou Elassad) #5

It’s ok, thanks it’s been solved.