Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Any recommendation for rain animation?
Started by TanvirIndie Jul 30 2018 10:17 AM

14 replies to this topic

Best Answer XeduR @Spyric , 31 July 2018 - 04:15 AM

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

Is there any sample code for rain animation I can use?



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,921 posts
  • Corona SDK

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. :(



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,921 posts
  • Corona SDK

This is the most basic rain I can think of:

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/07/10secondrain.zip

 

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()



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,921 posts
  • Corona SDK

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'.

 



[TOPIC: post.html]
#5

ldurniat

[GLOBAL: userInfoPane.html]
ldurniat
  • Contributor

  • 354 posts
  • Corona SDK

Hi ahmed_shahjada,

 

He even has a 'rain tutorial'.

 

I have prepared Corona version of this tutorial:) It available on Github.

 

Have a nice day:)

 

 

ldurniat



[TOPIC: post.html]
#6

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

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



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 6,921 posts
  • Corona SDK

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).


  • TanvirIndie likes this

[TOPIC: post.html]
#8

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Enthusiast

  • 69 posts
  • Corona SDK

  Best Answer

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.


  • TanvirIndie likes this

[TOPIC: post.html]
#10

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

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 :)

 

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.



[TOPIC: post.html]
#11

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

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.



[TOPIC: post.html]
#12

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Enthusiast

  • 69 posts
  • Corona SDK

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. 


  • TanvirIndie likes this

[TOPIC: post.html]
#13

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

Tried as you suggested, looks much better than what I did earlier and also not much of coding to do...



[TOPIC: post.html]
#14

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Enthusiast

  • 69 posts
  • Corona SDK

Good to hear!


  • TanvirIndie likes this

[TOPIC: post.html]
#15

TanvirIndie

[GLOBAL: userInfoPane.html]
TanvirIndie
  • Contributor

  • 121 posts
  • Corona SDK

Thanks...




[topic_controls]
[/topic_controls]