Some snow particles


(Nate ) #1

Hey guys! I was wondering what the best approach would be for having a snow storm appear to be occurring outside of a window.

Right now in the update method of my window sprite I have this:

                            var interval:int = 40;
			for (var o:int = 0; o < FP.width; o += interval)
			{
				emit.emit("snow", o + FP.camera.x, -10);
			}

This is code I got from here a little while ago! It works great but covers the whole screen, I am just looking to have the snow particles appear on the window sprite.

Thanks guys!


(JP Mortiboys) #2

You’ve got two issues here - first is to only have the particles spawn on the window, the second is to only show the particles inside the window and not let them move outside it.

The first is quite simple:

const particlesPerFrame:int = 100;
for (var i:int = 0; i<particlesPerFrame; i++) {
  emit.emit("snow", x + FP.rand(width), y);
}

The second is a little trickier - FP doesn’t allow you to make any meaningful changes to the Emitter class without core hacking, so masking the particles or detecting them leaving the window boundaries isn’t really feasible.

I would suggest having a relatively thick “pile of snow” graphic at the bottom of the window, positioned higher in z-index than the particles, then ensure that the absolute furthest a snow particle can travel downwards (based on distance and distanceRange in the setMotion() call) will not go beyond that graphic.


(Zachary Lewis) #3

Could you override Emitter.render to target a secondary BitmapData that you use as an Image which you could then mask?