[SOLVED] What's a good way to create rain/snow effects?


(Quang Tran) #1

I want to get rain and snow effects in my game.

I know an easy way would be to use a particle emitter and create it as big as the level and just shoot the particles down, but my levels can get kinda big, so I wonder if that would be too much of a drain for the game.

One solution I’ve tried is to create a particle emitter only as big as the game screen, and set it’s scroll factor to 0 so that it follows the camera. This ends up looking kinda weird since the particles follow the player.

Anyone have any alternative ideas?


(rostok) #2

I never used particle emitters but the old trick is to have two such objects with size of a game screen (assuming it is 2D game). Both emitters are positioned side by side and their X positions are snapped (they will not move with the camera). On every frame you have to check if emitter is still in the viewport, If it is not you either add or subtract screen’s width to its X making sure it will be visible.


(kgbkgb) #3

I just use a transparent weather image on top of everything but behind my gui. Scale it to the screen size and bam.


(Jacob Albano) #4

Since the emitter can emit particles at any point, you could do something like this:

var interval:int = 20;  // new snowflake every so many pixels
for (var i:int = 0; i < FP.width; i += interval)
{
    emitter.emit("snow", i + FP.camera.x, 0);
}

This way the particles that have already been spawned will track correctly against the scrolling camera, but new particles will always be spawned in view of the camera. You could easily modify the above code to emit in a buffer to the left and right of the screen’s edges to be more realistic when the screen scrolls over.


(Quang Tran) #5

Doy, the solution seems so simple now. Thanks guys! I decided to go with jacob’s solution. Appreciate all the alternative solutions though, very smart!


(Nate ) #6

Hello Jacob! I have implemented the code snippet that you posted here for my games snow. I have finished tweaking the particle to make it look convincing. The slight issue I am having now, is when I enable FP.console it starts at around 60 MB being consumed, and climbs steadily to about 80-90 then it drops back down to 50-60. When it drops back down to where it started, there is a visible “chu-chunk” in my game (lol) as in everything lags for a split second.

Is there a fix for this? I really want to have snow, but do not want to deal with a laggy game.


(Jacob Albano) #7

Flashpunk’s particle system is pretty efficient, but you still need to be careful with how many particles you have on screen at once. There’s no “fix” besides limiting yourself.


(Nate ) #8

Do you think it has something to do with my stage width being over 1280 pixels?