2
\$\begingroup\$

Oddly enough I cant find clear instructions on this theme (I only found rain and the method is very particular) so I ask, how do I implement a whole-screen snow-falling effect?

The methods i can think off the bat are:

-Using LibGDX's Particle System: But it seems like it will be overkill for some reason, i need the snow all over the screen and i have the idea that particle system is only optimized for ephemeral occasional particles (correct me if im wrong)

-Draw a giant animation that fills the entire screen Well, it also seems quite overkill... and it sounds hackish and dirty.

Id like a smooth effect, like a snowstorm, I cant think of any optimal method nor I have great experience in particles to be honest. So, any ideas?

P.S: The game is mainly for android, which is why Im so worried about an optimal solution

\$\endgroup\$
  • \$\begingroup\$ Another method would be to simply create snow flake sprites or even use a PixMap depending on the level of detail of your snow flakes. Then, just simply make them fall with a velocity with random x-axis variations. If you batch your drawings, I don't see how this will cause much of a slowdown, even with hundreds of snow flakes. \$\endgroup\$ – midasmax May 21 '14 at 0:33
  • \$\begingroup\$ Wont updating, lets say 100 snowflakes's positions, cause a slowdown tho? \$\endgroup\$ – Xkynar May 23 '14 at 9:47
  • \$\begingroup\$ If libGDX chokes on only 100 sprites being drawn at the same time, I would be very, very surprised. (But, it depends on your phone or PC, obviously.) 100 sprites is still quite few. \$\endgroup\$ – ashes999 May 23 '14 at 14:07
6
\$\begingroup\$

The particle system solution is likely the one you want as creating and maintaining 100+ sprites with varying positions and gravity is exactly what a particle system does. Only it will handle object re-use for you automatically which will help make it as efficient as possible.

Just create a line emitter that covers the entire width of your viewport. Place it slightly above the top of the camera viewport so that spawned snowflakes appear to drift into the frame. Give the particles a downward gravity and give them some horizontal jitter to simulate a drifting movement. Give each snowflake a random scale to simulate some sense of depth. You could even base the strength of gravity based on that scale to give a proper parallax. Maybe even lower the opacity of each particle based on how low the scale is to increase the sense of depth?

\$\endgroup\$
  • \$\begingroup\$ +1 this is a good answer and could become a great answer if you provide some (pseudo?-)code (and perhaps a snowflake image to illustrate the scaling. \$\endgroup\$ – ashes999 May 23 '14 at 14:07
  • 1
    \$\begingroup\$ You are right, Libgdx's particle system is the perfect solution for this, i was able to create a very nice snow effect from a single emitter :) thanks \$\endgroup\$ – Xkynar Jun 4 '14 at 3:10
2
\$\begingroup\$

Im using libgdx particle system for a snow effect here's the draft file ,this will need some tuning but a good start.
In this effect the png get some light blue tint.

You can simply import it

ParticleEffect snowEffect = new ParticleEffect();<br>
snowEffect.load(files.internal("snow_effect"), [files.internal("particle.png")][2]);<br>
snowEffect.start(); 

have to call the start method
...
and in the render loop you should call
snowEffect.draw(batch,deltaTime);
this will updating then drawing the effect,
there's a simple draw without the delta time , in that case u have to call the effect.update(deltaTime) before it.

ps:you need to position it to the top of the screen and match the width

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.