Is there any sample code for rain animation I can use?
No. That is a very broad question.
Show us a video with rain like you think rain should look.
Tell us how it should look. How should it interact with the scene and objects in the scene?
There are probably 100 ways to make rain… so answering is really unlikely to help much since the answer probably won’t match what you’re imagining rain to be.
You should put more effort into your questions if you want a better answer.
This is the most basic rain I can think of:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/07/10secondrain.zip
https://www.youtube.com/watch?v=gsFxYJy_-EM&feature=youtu.be
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ===================================================== local cx = display.contentCenterX local cy = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local left = cx - fullw/2 local right = cx + fullw/2 local top = cy - fullh/2 local bottom = cy + fullh/2 -- ===================================================== local raining = true local function newDrop( oy ) local x = cx + math.random( -fullw/2, fullw/2) local y = top - 100 - oy local endY = bottom + 100 local speed = math.random(200,500) local width = math.random(1,4) local height = math.random(10,25) local time = 1000 \* (endY - y)/speed local drop = display.newRect( x, y, width, height ) transition.to( drop, { y = endY, time = time, onComplete = display.remove } ) end local function doRain() if( not raining ) then return end for i = 1, 4 do newDrop( math.random(0, 200) ) end timer.performWithDelay( math.random(30,120), doRain ) end doRain()
I’d like to suggest too that you and other readers watch this guy:
https://www.youtube.com/user/shiffman
It isn’t Corona related, but he talks about a lot of great stuff.
He even has a ‘rain tutorial’.
Hi ahmed_shahjada,
I have prepared Corona version of this tutorial:) It available on Github.
Have a nice day:)
ldurniat
Thanks Idurniat and roaminggamer,
I think the last purple rain looks pretty code, will need to change color, speed and other attributes like angle too
Changing the angle will involve vector calculations or trig unless your drops are round.
In the case of round drops you the drop angle doesn’t need to align to the angle of motion (vice versa really).
At the moment I have modified some deprecated code to produce rain effect from
https://github.com/vsergeyev/Rain/tree/master/Rain
It is pretty good, the rain is striking at an angle. Although I need to increase the density of rain.
Image link : https://goo.gl/QvH1rn
You could also consider using particles. They are quite lightweight, easy to use and may prove more visually pleasing. You can read about particles for Corona at https://docs.coronalabs.com/api/library/display/newEmitter.html.
There are several different ways of creating particles for Corona projects. One easy method is using a free tool available at http://particle2dx.com/. Check the templates and select snow rain. You can then change the shape of the particle to a rectangle and tweak around with the other settings so that it better fits actual rain.
Out of curiousity, I just quickly tried out http://particle2dx.com/, and I tell you what, the snow effect looks excellent!
I also added corona code so that it uses the snow effect on game, and looks fantastic.
Thanks for the free tool!
I will try to tweak it so that it looks like rain, wonderful!
Adding this to my notes
Everyday is a learning day for me in corona, I am learning bits and pieces everyday. The particle effect and rain examples are awesome. Thanks everyone for the help. I am marking this thread as resolved.
I’m glad you like it.
To turn it into rain, all you really need to do is to select the rain snow template again, then go to “Color&Shape” tab and select the line shape (3rd from the right). Finally, adjust the “spin” sliders in both start and end segments to 110. This’ll provide you with a basic rain setup.
The best part about using particles in Corona is that you can also tweak them on the go in game, which means that you can adjust the speed, amount, size, direction, colour etc. of the rain with ease.
Tried as you suggested, looks much better than what I did earlier and also not much of coding to do…
Good to hear!
Thanks…
No. That is a very broad question.
Show us a video with rain like you think rain should look.
Tell us how it should look. How should it interact with the scene and objects in the scene?
There are probably 100 ways to make rain… so answering is really unlikely to help much since the answer probably won’t match what you’re imagining rain to be.
You should put more effort into your questions if you want a better answer.
This is the most basic rain I can think of:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/07/10secondrain.zip
https://www.youtube.com/watch?v=gsFxYJy_-EM&feature=youtu.be
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ===================================================== local cx = display.contentCenterX local cy = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local left = cx - fullw/2 local right = cx + fullw/2 local top = cy - fullh/2 local bottom = cy + fullh/2 -- ===================================================== local raining = true local function newDrop( oy ) local x = cx + math.random( -fullw/2, fullw/2) local y = top - 100 - oy local endY = bottom + 100 local speed = math.random(200,500) local width = math.random(1,4) local height = math.random(10,25) local time = 1000 \* (endY - y)/speed local drop = display.newRect( x, y, width, height ) transition.to( drop, { y = endY, time = time, onComplete = display.remove } ) end local function doRain() if( not raining ) then return end for i = 1, 4 do newDrop( math.random(0, 200) ) end timer.performWithDelay( math.random(30,120), doRain ) end doRain()
I’d like to suggest too that you and other readers watch this guy:
https://www.youtube.com/user/shiffman
It isn’t Corona related, but he talks about a lot of great stuff.
He even has a ‘rain tutorial’.
Hi ahmed_shahjada,
I have prepared Corona version of this tutorial:) It available on Github.
Have a nice day:)
ldurniat
Thanks Idurniat and roaminggamer,
I think the last purple rain looks pretty code, will need to change color, speed and other attributes like angle too