Snow effect

Hi guys,

Just wondering if anyone can help with this one. I’m making a festive game and really want to add in a snow effect, simple snow falling nothing to complex - Does anyone know where I maybe able to find code, or how to create this? I know theres a particle plugin, however I was also wondering if i can great this by a little bit a code.

Thank you all in advance,
Cheers,
Chris [import]uid: 43642 topic_id: 33139 reply_id: 333139[/import]

Hi Chris,

Can you give us some more information on the game. For example, is it a top-down game, side view etc? How big are your snow flakes, do you want them to be spec size or noticably large enough to see the flake etc. How dense do you want the snow to be? A hell of a lot of specs on the screen or a new flake every 2 seconds or so?

Assuming you want to draw a new flake every 2 seconds using an image of a flake. You could have a Runtime listenercalling a createNewFlake() function which draws a New Image Object (flake) to screen every 2000ms and positions the flake object at a random X position and the Y is just off the top of the screen.

Each flake object can have it’s own properties forcing it to fall in a downward direction using the applyForce() function and the applyTorque() function can give them a bit of a twirl as they fall.

Does that make sense?

Michael Piercy
Pixel Wolf Studios [import]uid: 156990 topic_id: 33139 reply_id: 131574[/import]

Let me take a quick stab… totally untested.

local function removeFlake(target)  
 target:removeSelf()  
 target = nil  
end  
  
local function spawnSnowFlake()  
 local flake = display.newCircle(0,0,2)  
 flake.x = math.random(display.contentWidth)  
 flake.y = -2  
 local wind = math.random(80) - 40  
 transition.to(flake,{time=math.random(3000) + 3000, y = display.contentHeight + 2, x = flake.x + wind, onComplete=removeFlake})  
end  
  
local function makeSnow(event)  
 if math.random(10) == 1 then -- adjust speed here by making the random number higher or lower  
 spawnSnowFlake()  
 end  
 return true  
end  
  
Runtime:addEventListener("enterFrame",makeSnow)  

A more complicated version would be to use the physics engine to add some better floating and wind like effects. Of course you probably want images instead of circles too.
[import]uid: 19626 topic_id: 33139 reply_id: 131576[/import]

Hi there,

Thank you so much for the above, the game is a endless runner, landscape moving right - I will show my develop the above and let you know how it goes.

Again, thank you for taking the time to get back to my post, thats very kind of you.

Cheers,
Chris [import]uid: 43642 topic_id: 33139 reply_id: 131582[/import]

No problem Chris,

Best of luck with your project.

Michael Piercy
Pixel Wolf Studios [import]uid: 156990 topic_id: 33139 reply_id: 131602[/import]

Hi Chris,

Can you give us some more information on the game. For example, is it a top-down game, side view etc? How big are your snow flakes, do you want them to be spec size or noticably large enough to see the flake etc. How dense do you want the snow to be? A hell of a lot of specs on the screen or a new flake every 2 seconds or so?

Assuming you want to draw a new flake every 2 seconds using an image of a flake. You could have a Runtime listenercalling a createNewFlake() function which draws a New Image Object (flake) to screen every 2000ms and positions the flake object at a random X position and the Y is just off the top of the screen.

Each flake object can have it’s own properties forcing it to fall in a downward direction using the applyForce() function and the applyTorque() function can give them a bit of a twirl as they fall.

Does that make sense?

Michael Piercy
Pixel Wolf Studios [import]uid: 156990 topic_id: 33139 reply_id: 131574[/import]

Let me take a quick stab… totally untested.

local function removeFlake(target)  
 target:removeSelf()  
 target = nil  
end  
  
local function spawnSnowFlake()  
 local flake = display.newCircle(0,0,2)  
 flake.x = math.random(display.contentWidth)  
 flake.y = -2  
 local wind = math.random(80) - 40  
 transition.to(flake,{time=math.random(3000) + 3000, y = display.contentHeight + 2, x = flake.x + wind, onComplete=removeFlake})  
end  
  
local function makeSnow(event)  
 if math.random(10) == 1 then -- adjust speed here by making the random number higher or lower  
 spawnSnowFlake()  
 end  
 return true  
end  
  
Runtime:addEventListener("enterFrame",makeSnow)  

A more complicated version would be to use the physics engine to add some better floating and wind like effects. Of course you probably want images instead of circles too.
[import]uid: 19626 topic_id: 33139 reply_id: 131576[/import]

Hi there,

Thank you so much for the above, the game is a endless runner, landscape moving right - I will show my develop the above and let you know how it goes.

Again, thank you for taking the time to get back to my post, thats very kind of you.

Cheers,
Chris [import]uid: 43642 topic_id: 33139 reply_id: 131582[/import]

No problem Chris,

Best of luck with your project.

Michael Piercy
Pixel Wolf Studios [import]uid: 156990 topic_id: 33139 reply_id: 131602[/import]