Hey,
Was just wondering if there was a way of adding Christmas effects to an app in Corona ?
Maybe something along the lines of falling show etc ?
Thank you
Hey,
Was just wondering if there was a way of adding Christmas effects to an app in Corona ?
Maybe something along the lines of falling show etc ?
Thank you
Actually, falling snow is quite a nice effect to add and is pretty easy. It’s also a great learning curve to practice on.
The basics are to create a single function which randomly generates a just off-screen particle, say a white, small circle, and create a transition to make it run down the screen from a random point to a random point in a random time. Give it an onComplete event handle to call itself and have the particle rest to the top of the screen. Then you just call that function 10 or 20 times and let it run. Maybe give the transitions a tag of “snow” so you can pause them or cancel them all in one go.
Try that and see how you get on.
The interesting thing is that when you’ve mastered that routine, modifying it to make swirling vortices, rising fire particles or gusts of dust and leaves is quite straight forward.
Here’s one I knocked up in under 10 minutes:
-- snow example display.setStatusBar( display.HiddenStatusBar ) display.setDefault( "background", .05,.05,.2 ) local snowGroup = display.newGroup() local function snowDrop( flake ) if (flake == nil) then local flake = display.newCircle( snowGroup, 0, 0, 2 ) flake:setFillColor( .9,.9,.9 ) snowDrop( flake ) else flake.x, flake.y = math.random( 0, display.actualContentWidth ), -10 local xTarget, yTarget = math.random( 0, display.actualContentWidth ), display.actualContentHeight+10 transition.to( flake, { x=xTarget, y=yTarget, delay=math.random( 0, 5000 ), time=math.random( 3000, 10000 ), tag="snow", onComplete=snowDrop } ) end end for i=1, 50 do snowDrop() end
Hey! Just thought id throw in a demo i had laying around!
local physics = require("physics") physics.start() local snow = {} local sCounter = 1 local sTimer local function spawnSnow() local xRandom = math.random(display.contentCenterX - 200, display.contentCenterX + 200) local xRandomVelocity = math.random( -50, 51 ) snow[sCounter] = display.newCircle( xRandom, -200, 3 ) snow[sCounter]:setFillColor( 1, 1, 1 ) physics.addBody( snow[sCounter], "dynamic", { isSensor = true } ) snow[sCounter].gravityScale = 0 snow[sCounter]:setLinearVelocity( xRandomVelocity, 100 ) snow[sCounter].value = sCounter sCounter = sCounter + 1 end sTimer = timer.performWithDelay( 100, spawnSnow, -1 )
This one uses physics. I guess ones better than the other considering you have physics or not.
Good Luck!
In a different way, you can also use a dedicated particle engine for this. Some examples (sorry for the shameless plug, but I’m pretty much the only current particle effects guy around after Particle Candy kind of died) are my new particle effects library, Prism, CBE, or Corona’s built-in particle effects.
@SonicX278: Don’t forget to eventually delete your snowflakes!
Yes i was going to add a collision detection to delete them but didn’t know if i should. If you are trying to add this effect into your lets say menu then you could just remove the whole table and its contents when leaving the scene!
Like this!
timer.performWithDelay(1, function() for k,v in pairs( snow ) do display.remove( v ) end snow = {} end )
Good luck!
Actually, falling snow is quite a nice effect to add and is pretty easy. It’s also a great learning curve to practice on.
The basics are to create a single function which randomly generates a just off-screen particle, say a white, small circle, and create a transition to make it run down the screen from a random point to a random point in a random time. Give it an onComplete event handle to call itself and have the particle rest to the top of the screen. Then you just call that function 10 or 20 times and let it run. Maybe give the transitions a tag of “snow” so you can pause them or cancel them all in one go.
Try that and see how you get on.
The interesting thing is that when you’ve mastered that routine, modifying it to make swirling vortices, rising fire particles or gusts of dust and leaves is quite straight forward.
Here’s one I knocked up in under 10 minutes:
-- snow example display.setStatusBar( display.HiddenStatusBar ) display.setDefault( "background", .05,.05,.2 ) local snowGroup = display.newGroup() local function snowDrop( flake ) if (flake == nil) then local flake = display.newCircle( snowGroup, 0, 0, 2 ) flake:setFillColor( .9,.9,.9 ) snowDrop( flake ) else flake.x, flake.y = math.random( 0, display.actualContentWidth ), -10 local xTarget, yTarget = math.random( 0, display.actualContentWidth ), display.actualContentHeight+10 transition.to( flake, { x=xTarget, y=yTarget, delay=math.random( 0, 5000 ), time=math.random( 3000, 10000 ), tag="snow", onComplete=snowDrop } ) end end for i=1, 50 do snowDrop() end
Hey! Just thought id throw in a demo i had laying around!
local physics = require("physics") physics.start() local snow = {} local sCounter = 1 local sTimer local function spawnSnow() local xRandom = math.random(display.contentCenterX - 200, display.contentCenterX + 200) local xRandomVelocity = math.random( -50, 51 ) snow[sCounter] = display.newCircle( xRandom, -200, 3 ) snow[sCounter]:setFillColor( 1, 1, 1 ) physics.addBody( snow[sCounter], "dynamic", { isSensor = true } ) snow[sCounter].gravityScale = 0 snow[sCounter]:setLinearVelocity( xRandomVelocity, 100 ) snow[sCounter].value = sCounter sCounter = sCounter + 1 end sTimer = timer.performWithDelay( 100, spawnSnow, -1 )
This one uses physics. I guess ones better than the other considering you have physics or not.
Good Luck!
In a different way, you can also use a dedicated particle engine for this. Some examples (sorry for the shameless plug, but I’m pretty much the only current particle effects guy around after Particle Candy kind of died) are my new particle effects library, Prism, CBE, or Corona’s built-in particle effects.
@SonicX278: Don’t forget to eventually delete your snowflakes!
Yes i was going to add a collision detection to delete them but didn’t know if i should. If you are trying to add this effect into your lets say menu then you could just remove the whole table and its contents when leaving the scene!
Like this!
timer.performWithDelay(1, function() for k,v in pairs( snow ) do display.remove( v ) end snow = {} end )
Good luck!