Page 1 of 2 12 LastLast
Results 1 to 15 of 26

Thread: Hardcore Particles

  1. #1

    Hardcore Particles

    Hey, a recent post on the forums got me thinking about particles and bitmapData. Now ive never attempted anything like this before so what i am going to show you may blind you with my hideous ideas + code, but basicly ive used the same principles as Sirsian's Bunny code.

    Anyway tbh, it has come out pretty well... but i can do about 300 particles before it chugs and i have seen 10000 particles running smooth, so my code obviously has flaws. Can someone explain to me where im going wrong and what i should be doing!?

    Below is a rar with all the files!!

    Ty in advance guys!
    Attached Files Attached Files

  2. Quote Originally Posted by Krabex View Post
    Hey, a recent post on the forums got me thinking about particles and bitmapData. Now ive never attempted anything like this before so what i am going to show you may blind you with my hideous ideas + code, but basicly ive used the same principles as Sirsian's Bunny code.

    Anyway tbh, it has come out pretty well... but i can do about 300 particles before it chugs and i have seen 10000 particles running smooth, so my code obviously has flaws. Can someone explain to me where im going wrong and what i should be doing!?

    Below is a rar with all the files!!

    Ty in advance guys!
    Argh, I can't open it with flash8, I guess it's AS3.0? By looking at the classes I immidiately notice two things:

    One, why do you have a pCount? If you push every particle in an array simply use pArray.Length. This is a bit more dynamic. This will not necessarily speed things up though.

    Two, why do you create a new Rectangle when you're rendering? This very slow since you do this for every particle every time it is rendered. If you have different sizes of particles atleast just save it in the constructor. Even better would be to reference it to 1 rectangle. I'm pretty sure doing this will speed things up significantly.

    EDIT:

    You're also using memory with saving the xSpeed and ySpeed, even the gravity shouldn't be a local variable. I still don't think this is what's causing the huge *** difference though. But I'll keep looking

    Again, save rectangles if they're not changing (in the render method of Emitter.as). I'm not sure what screen.fillRect and screen.applyFilter does but I'm pretty sure blur WILL take a lot of memory. Try it without the filters it's atleast worth a shot.

    Also, you're particles are 4x4 = 16 pixels. The examples you talked about might have 1 pixel particles. Which means they wouldn't even have to use copyPixels but rather .setPixel(x, y, color). Which could be a freaking lot faster. That might actually explain a lot xD
    Last edited by ArmoredSandwich; July 4th, 2008 at 12:04 PM.

  3. #3
    Some good ideas there, i will take into account what you have said... thanks

  4. #4
    One, why do you have a pCount? If you push every particle in an array simply use pArray.Length
    important to notice that you should never loop something like this;

    for (var i:int = 0; i < pArray.length; i++) {
    };

    didn't check the file, sorry. Bit lazy.

    I posted a particle experiment on my blog, feel free to download the source and check it out.

  5. Quote Originally Posted by sekasi View Post
    important to notice that you should never loop something like this;

    for (var i:int = 0; i < pArray.length; i++) {
    };
    And why is that?

  6. #6
    TheCanadian's Avatar
    10,248
    posts
    Noo doot aboot it, eh?
    Because it recounts the number of elements in the array every time it is called which is slower than just counting once and storing the value in a variable.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  7. #7
    Code:
    var len:Number = pArray.length;
    for ( var i:int = 0; i < len; i++) {
    
    }

  8. Hmm I suppose that's true, I thought of that actually, but I thought there was a better answer to be honest. I mostly have arrays that are not static. And I can't believe McGuffin's code is faster, quite the opposite actually.

  9. #9
    Quote Originally Posted by ArmoredSandwich View Post
    Hmm I suppose that's true, I thought of that actually, but I thought there was a better answer to be honest. I mostly have arrays that are not static. And I can't believe McGuffin's code is faster, quite the opposite actually.
    That seems a strange assumption. The idea behind declaring a variable is that it will remain constant, using pArray.length inside of the FOR loop declaration means that every time the FOR loop goes through, it needs to recheck the pArray.length property to see if it changed during a previous loop.

  10. #10
    TheCanadian's Avatar
    10,248
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by ArmoredSandwich View Post
    Hmm I suppose that's true, I thought of that actually, but I thought there was a better answer to be honest. I mostly have arrays that are not static. And I can't believe McGuffin's code is faster, quite the opposite actually.
    Well, it is.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  11. #11
    Quote Originally Posted by ArmoredSandwich View Post
    Hmm I suppose that's true, I thought of that actually, but I thought there was a better answer to be honest. I mostly have arrays that are not static. And I can't believe McGuffin's code is faster, quite the opposite actually.
    It's not only faster, it's exponentially faster.

  12. #12
    Quote Originally Posted by TheCanadian View Post
    Well, it is.
    Indeed, sorry Armor'd Sandwich

    I've read that using while loops can also be faster than for loops, but that was a long time ago and it was written for AS2. Things might have changed since then. I can't find the link to that article either, so you'll just have to take my word for it until someone runs some tests
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  13. I believe you guys, of course I do I guess I'll run some benchmark tests to see how big the difference is.

  14. #14
    Yes back to topic at hand , i redid my code but with set pixel and some other little tweaks, now i can spawn 2000 particles at a time without any lag, but any higher and fps drops dramaticly.

    Any other techniques i can try to really get the most out of this ?

  15. #15
    attach your new code, I'll try and see if I'm able to improve anything (prolly not! )

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012