Falling Snow effect , Particles and Performance

IceboxIcebox Member Posts: 1,485
edited October 2015 in Miscellaneous

Hello guys , just wanted to share some info on particles, I wanted to do a falling snow effect for my platformer game so I made an actor with particle behavior:

Number of Particles 100
Particle Startup Time: 20 seconds
Particle Life Time : 20 seconds

The 100 particles will spawn in a duration of 20 seconds ( Particle Startup Time) . After 20 seconds they will loop once your particle life time is done , so I put the startup time and particle lifetime the same to create a never ending loop.

My scene Width is 13,000 and Height is 1000

So I put the X position to random (( 0 , 13000)) and Y position to 1000 , relative to scene.
The min is going to be 0 and maximum will be 13000 , so this way I dont need to place my actor inside the scene , I can have it placed on the left side.

Direction is 270 down

Speed = Random ((60,120)) so the speed will range between that.

Now all I had to do is place the actor on the left side of the scene. Like this

And the result is this

Regarding Performance , I wanted more than 100 particles obviously , so I put 5000 particles , but this slowed my game so much , it dropped the frames to 25 frames per second . So instead I put the number of particles 500 , and have 10 actors and the result is 58-60 frames per second.

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    @Icebox1910 said:
    My scene Width is 13,000 and Height is 1000

    So I put the X position to random (( 0 , 13000)) and Y position to 1000 , relative to scene.

    If I understand this correctly (and I'm going to guess your project is iPad landscape) this is very inefficient, you have particles spawning across the entire 13,000 pixel range when you can only see a range of 1024 pixels at anyone time ? And starting the particles at y1000 means they will be moving off-screen (if my guess at a landscape iPad is right), I'd limit the X range to just the width of the camera (and possibly extra pixels either side) and start the particles just off the top of the scene.

  • IceboxIcebox Member Posts: 1,485
    edited October 2015

    @Socks Its on iphone landscape , my scene width is 13,000 , its a long level , so I want it to spawn at any x position , My screen height is 1000 , I want it to spawn from that height above , if i do it your way with the width of the camera it might cause bugs on other devices , I noticed that not all devices work the same way , so im spawning it at the scene size not camera. Also , this would make it look like its unscrollable , the effect wouldnt look nice , i didnt try it but I think it wouldnt look good cause the snow drop will fall and move along with the camera as you move.

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    @Socks said:
    If I understand this correctly (and I'm going to guess your project is iPad landscape) this is very inefficient, you have particles spawning across the entire 13,000 pixel range when you can only see a range of 1024 pixels at anyone time ? And starting the particles at y1000 means they will be moving off-screen (if my guess at a landscape iPad is right), I'd limit the X range to just the width of the camera (and possibly extra pixels either side) and start the particles just off the top of the scene.

    I agree. There no sense in spawning extra snow that you aren't going to see. Just spawn enough snow that if the camera comes into view of an area snow is falling. You could spawn a 1000 pixels behind and ahead and this would be more efficient than spawning randomly over 13k pixels.

  • IceboxIcebox Member Posts: 1,485

    Would it look good though ? cause I tried it , and the problem is , I move and the snow moves along with the camera making it look bad , so this way you pass the snow and it doesnt get stuck with you on the screen while your moving

  • SocksSocks London, UK.Member Posts: 12,822

    @Icebox1910 said:
    Socks Its on iPhone landscape . . .

    Could mean lots of things, iPhone 4 (!), iPhone 5, iPhone 6, iPhone 6 plus ?

    @Icebox1910 said:
    my scene width is 13,000 , its a long level , so I want it to spawn at any x position , My screen height is 1000 , I want it to spawn from that height above

    You screen height cannot be 1000 pixels ! :smile:

    @Icebox1910 said:
    if i do it your way with the width of the camera it might cause bugs on other devices

    If set up correctly there would be no issue.

    @Icebox1910 said:
    Also , this would make it look like its unscrollable , the effect wouldnt look nice , i didnt try it but I think it wouldnt look good cause the snow drop will fall and move along with the camera as you move.

    Lol, I didn't mean lock the snow drops to the camera so that they move with it !?! :smile: Like you say they would look terrible !

    I mean only spawn the snow in the area that you can see, if you are at (for example) x400, do you really want the phone to be calculating and moving particles across thousands of pixels you cannot see ? So while you are up at the x400 end doing your thing, there are hundreds of particles falling at x1000 and x2400 and x3211 and x4400 . . . . . all the way across to x13,000 !

    Like I say if this question is primarily about efficiency ("Particles and Performance"), then the method you are using is very inefficient, populating a vast scene with particles of which you can only ever see 4.5% (guessing an iPhone 5 project) is an enormous waste of processor power.

  • SocksSocks London, UK.Member Posts: 12,822

    @RabidParrot said:
    You could spawn a 1000 pixels behind and ahead . . .

    Yeah, I was thinking a screen's width either side, so when you move into that area they are already up and running.

  • SocksSocks London, UK.Member Posts: 12,822

    @Icebox1910 said:
    Would it look good though ? cause I tried it , and the problem is , I move and the snow moves along with the camera making it look bad . . .

    It will look bad if the snow moves with the camera, the answer seems obvious enough, don't move the snow with the camera ! :smile:

  • IceboxIcebox Member Posts: 1,485

    @Socks I kind of understand now, I thought the particles are moving with the camera if i make them spawn at the camera width , lets say a particle spawns , and its falling down , if i move my actor to the right wouldnt it move along with it ? since its limit is the x range of the camera ? I didnt try it and I really dont know how to implement this , would i have to unlock the actor ? to access camera and do it ? any tips would be good

  • SocksSocks London, UK.Member Posts: 12,822

    @Icebox1910 said:
    Socks I kind of understand now, I thought the particles are moving with the camera if i make them spawn at the camera width , lets say a particle spawns , and its falling down , if i move my actor to the right wouldnt it move along with it ? since its limit is the x range of the camera ? I didnt try it and I really dont know how to implement this , would i have to unlock the actor ? to access camera and do it ? any tips would be good

    I've made you a quick illustration of what I mean, use the arrow keys to move the camera left and right through the scene (the pale blue strip), notice how within the camera area (the black outline) it is always snowing.

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    @Icebox1910 said:
    Socks I kind of understand now, I thought the particles are moving with the camera if i make them spawn at the camera width , lets say a particle spawns , and its falling down , if i move my actor to the right wouldnt it move along with it ? since its limit is the x range of the camera ? I didnt try it and I really dont know how to implement this , would i have to unlock the actor ? to access camera and do it ? any tips would be good

    The movement of the snow really depends on the particle behavior and the layer that the snow is on. Is it scrollable or not scrollable?

  • IceboxIcebox Member Posts: 1,485
    edited October 2015

    @Socks Oh my , I cant believe how I couldnt think of it this way , I always created a particle actor thats why i was confused , but I should have just added this on my main actor or camera. Thanks alot

  • IceboxIcebox Member Posts: 1,485

    @RabidParrot Yea cause my actor didnt have any moving rule so I couldnt get how I was supposed to make it snow in front of the camera and behind , but now i get it. thanks

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited October 2015
  • IceboxIcebox Member Posts: 1,485

    @Hopscotch Yea for some reason I always had another actor that controls the particles , so i used to drop around 50 actors on screen and scatter them around when I could have just done this and then as i post it here i find another way to do it much better , I have to think better next time :D

Sign In or Register to comment.