2
\$\begingroup\$

I wish to achieve a snowing effect on my game. The game is made in LibGDX and im using ParticleEmitter. I created a snow effect in ParticleEditor which consists in a line which spawns snow flakes. The problem is:

First, and the most important, since the game movement is vertical (its a jumper), if i just place the line above the screen, the jumping makes it look unnatural since when im jumping up, and the camera follows me, the particle emitter also has to move up, and the snow flakes are spawned with a bigger vertical distance; And when Im going down from the jump, a section of closer snowflakes is spawned due to that occurence. That makes the snow visually inconsistent.

Second, i wanted the snow to show up filling the screen from the start, instead of it starting to follow when the emitter is started.

To try to fix the first problem, i made the snow screen static, but it looks horrible, i really want the feeling that the snow is falling and my character is going up against it.

Any ideas how to achieve such an effect?

\$\endgroup\$

5 Answers 5

1
\$\begingroup\$

Another option would be to spawn a fixed number of snow particles and make them teleport to the top when they reach the bottom of the screen. This is trivial but in your case it should work fine.

\$\endgroup\$
4
  • \$\begingroup\$ This is actually very smart, but is it possible to follow this idea and still use LibGDX's Particle System? \$\endgroup\$
    – Xkynar
    Commented Aug 1, 2014 at 14:02
  • \$\begingroup\$ @Xkynar I don't think so. You'd have to create your own list of particles, because it seems you can't move individual particles, so you couldn't teleport them. I am not a LibGDX expert though, so maybe someone with more experience than me can answer that. \$\endgroup\$ Commented Aug 1, 2014 at 14:07
  • \$\begingroup\$ Grrr, i doubt a particle system made by me would be as optimized as LibGDX's... A simple particle system isnt a hard thing to do, but id have to study about optimizations on that subject and I really didnt want to waste time on such a minor (but elegant) detail \$\endgroup\$
    – Xkynar
    Commented Aug 2, 2014 at 2:09
  • \$\begingroup\$ @Xkynar A simple particle system should be as fast as LibGDX's one. They added a lot of stuff to theirs, and there isn't much optimization you can apply to particles... \$\endgroup\$ Commented Aug 2, 2014 at 17:57
2
\$\begingroup\$

Does the screen have game interaction or impact? Is it necessary to draw it in the same pass as the rest of the world, or even with the same camera for that matter? If the snow is mostly acting as an aesthetic overlay then do your render in two passes:

  1. Begin render. Render your world using the dynamic world camera. End render.
  2. Begin snow render. Render your snow using a static camera. End render.

EDIT

I'd aim for something like this: Snow Camera Overlay

The black box represents the world for your jumper. The red box represents the small world-bound dynamic camera that follows your character. The blue box represents the snow camera which is larger than what the world camera will ever perceive at once, and which remains static.

I don't see any reason this kind of setup wouldn't give you the effect you're after, but I'm happy to discuss it with you! :)

EDIT 2

I forgot to address your jumping issue, sorry. You want a basic version of parallax scrolling there. What you could do is adjust the snow camera in the opposite direction of the jumper's velocity. So as he jumps up the snow will move down in tandem. Just make sure your snow camera size allows edge room for max jump distance.

\$\endgroup\$
3
  • \$\begingroup\$ it is simply an aesthetic overlay, but i want it to look "realistic". The problem with a static screen is that when my hero jumps, it doesnt look like im going up the snow. Instead, the snow looks like a lousy .gif i just glued infront of my game screen. \$\endgroup\$
    – Xkynar
    Commented Aug 1, 2014 at 14:05
  • \$\begingroup\$ See, the problem is, your example aims for an horizontal platformer, mine is vertical (its an infinite jumper), hence the complications about having a falling snow screen, in the way you are saying, my "static screen" would have to be infinite since i can infinitely go up \$\endgroup\$
    – Xkynar
    Commented Aug 1, 2014 at 16:35
  • \$\begingroup\$ I see! That does make my solution not work. I'll think on it some more for you. :) \$\endgroup\$
    – Matt Sams
    Commented Aug 1, 2014 at 16:58
1
\$\begingroup\$

Try not to think in screen position, but world position. Place the emitter above the camera position with some offset each frame and spawn particles from there.

\$\endgroup\$
2
  • \$\begingroup\$ Thats what im doing. Thats not the point. The fact that I move the emitter each frame makes it so that the spawning is inconsistent. Imagine ur dropping sand from your hand. If you move your hand up, the flow of sand will reduce because by going up ur giving vertical distance between the spawns. That is what i dont want. \$\endgroup\$
    – Xkynar
    Commented Jul 31, 2014 at 17:02
  • 1
    \$\begingroup\$ @Xkynar An easy fix for this would be to place your emitter higher above the camera. This way, you need to create longer lived particles, but the inconsistency should go away with a little tweaking. \$\endgroup\$ Commented Aug 1, 2014 at 13:14
1
\$\begingroup\$

Without being able to modify the position of the individual particles, I don't think you're going to be able to achieve what you're looking for.

Take a look at a live wallpaper that I made, source available here. What I do here is I track each particle individually, and I can move them according to the rules set by the appropriate system. If a particle hits the bottom, it gets spawned at the top.

A few edits and you could achieve what you're looking for:

  • Add wind direction and a "sway" (could just be a sine wave with variable speed).
  • Make it so that particles hitting the bottom spawn at the top.
  • Make the spawn area have random y-position, so that the particle don't follow the exact pattern.
  • Add a "speed" modifier, make it so that particles can go both ways at variable speed. Then plugin a negative speed as your character begins to fall, with speed being proportional to your character speed.

Do note that the libraries I use may be outdated. I'm also not certain if my entity-component structure would be compatible with your existing game structure.

\$\endgroup\$
0
\$\begingroup\$

Not familiar with LibGDX Particle Emitters especially, but according to this site one of the options for a particle is attached, which makes the

particles stay the same distance away from the emitter regardless of movement

This is somewhat confirmed by the official github-wiki, though the documentation is not 100% clear too me regarding this point. The Options are described at the bottom of the page just before loading Particle Effects in your game and described as:

Attached: Means existing particles will move when the emitter moves.

If I understoond you correctly, this is what you're asking for.

For your information: Can also be found as first result when googleling "LibGDX move particles with emitter".

\$\endgroup\$
4
  • \$\begingroup\$ That is no good since "attaching" the particles to the emitter would give the exact same effect as if i used a static camera. The visual effect is really weird and unnatural. \$\endgroup\$
    – Xkynar
    Commented Aug 2, 2014 at 0:33
  • \$\begingroup\$ @Xkynar ok, so basically you want your snowflakes fall down when moving upwards and "fall" upwards when moving downwards, while the snowflakes have a base down-velocity. In other words -player.velocity.y + baseFallSpeed where baseFallSpeed is a negative Value? \$\endgroup\$
    – JFBM
    Commented Aug 2, 2014 at 0:51
  • \$\begingroup\$ well ye, but id prefer achieving such with LibGDX's native particle system. Althought it seems impossible and im guessing ill have to roll my own to get such features.. \$\endgroup\$
    – Xkynar
    Commented Aug 2, 2014 at 1:28
  • \$\begingroup\$ i even tried modifying the delta value of the update, but since the snow also moves a little to the right, when I jump the snow doesnt only move faster vertically, so it doesnt work visually. \$\endgroup\$
    – Xkynar
    Commented Aug 2, 2014 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .