A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: [SHOWOFF] Super-fast mass collision and 'particles'

  1. #1
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590

    [SHOWOFF] Super-fast mass collision and 'particles'

    Thanks to the suggestions of board members here on FK (and especially iopred, who actually showed me the source to his particle handling engine), I've been able to boost Invasion to phenomenal speeds.

    http://www.birchlabs.co.uk/Invasion5.swf

    This is firing 100 arrows per second, and there are 100 troops on the battlefield. Doing this without BitmapData would run, I think, at less than 1 fps (especially in high quality mode). I get from 16 to about 25 (slows down as more arrows are released, speeds up again when the castle's reloading).

    So, what do you think of the speed? I've still got to turn a couple of things into bitmaps, but besides that I've used every speed boost I could think of (and a few others that I'd been told).
    http://www.birchlabs.co.uk/
    You know you want to.

  2. #2
    Senior Member
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    101
    god, so mne movie clips
    Such little speed

    I wonder where that thread went now, need to save cuz I can see its useful =)
    grats man, hope the final product brings a couple of smiles ^^
    Your skill in reading has increased by 1.

  3. #3
    Senior Member TheLostGuru's Avatar
    Join Date
    Aug 2004
    Location
    I live on this webpage...
    Posts
    784
    *jaw drops slightly. Very nice work. No real noticable slow down on my computer.
    "If I have seen further it is by standing on the shoulders of giants." Isaac Newton
    ------------------------------------------------------------------------------

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Location
    Manchester, UK
    Posts
    2,357
    very cool...freaked me out when I refreshed it n suddenly it was night time

    RipX

  5. #5
    Senior Member
    Join Date
    Jun 2001
    Posts
    290
    nice work....I;m getting between 22-25 fps .....are you still using the attachBitmap()/scrollRect combo for these?

    EDIT: are you doing pixel-level collision detection using the hitTest bmp method?


    paul.

  6. #6
    Heli Attack! iopred's Avatar
    Join Date
    Jun 2003
    Location
    Sydney, Australia
    Posts
    923
    Great work, you did it!

    "Defend the Castle 2" looks to be a winner!
    Christopher Rhodes
    squarecircleco.

  7. #7
    Member
    Join Date
    Nov 2006
    Posts
    93
    No speed loss, worked perfectly. Very nice indeed.

  8. #8
    Style Through Simplicity alillm's Avatar
    Join Date
    Mar 2004
    Location
    Wales
    Posts
    1,988
    Good job mate. Glad to see you got it running smoothly. Looking forward to playing the finished game

    Ali

  9. #9
    Please, Call Me Bob trogdor458's Avatar
    Join Date
    Aug 2006
    Location
    Pensacola, FL
    Posts
    915
    holy moses, that runs great. looks like you'll be able to pull out alot of neat tricks with such optimization

    those knights never stand a chance

  10. #10
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    Good work big V.

    Looks like I've got a bit more to do on my shooter to compete with that

    Squize.

  11. #11
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    RipX, glad you appreciate the random backgrounds.

    Pentru, yup, I'm using iopred's attachBitmap()-based engine to make the troops and arrows, then looping trhrough them and running scrollRect() to choose which frame they display (that's right, the arrows are bitmaps. No _rotation usage, I just drew a sprite sheet with every 5 that the arrow could rotate through, and used atan2() to choose which frame to set it on).

    Not using pixel-level collision. What I'm doing is splitting the map up into 10 pixel wide sectors, and keeping an array of which troops are in which sectors. Then when the arrow is low enough to hit something, it'll kill the first element in the array of the sector it's in. No collision, loops, or clever maths required. Just craftiness.

    Iopred, I think I'll work on 'Attack the castle 5' before 'Defend your castle 2' but you never know. Was this particle engine the one you used in Heli Attack 3?

    At first I was using mr_malee's suggestion of getColorBoundsRect() to work out if it was worth checking for collisions that frame, but I lost a lot of fps by running constantly, so I ditched it.

    Ways I can see to make this even faster:

    Use less arrows and troops (duh!)
    Turn the castle into a bitmap
    Instead of using atan2() on the fly, make an array of pre-calculated results for it.
    Use flipflopping for collision detection (but the arrows are already pretty inaccurate as it is, and the collisions are extremely fast anyway, so I'm not gonna try it).
    http://www.birchlabs.co.uk/
    You know you want to.

  12. #12
    Flash hates me. crashlanding's Avatar
    Join Date
    Nov 2003
    Location
    UK
    Posts
    439
    23-26 fps here. Amazing work.
    "wen i found my gerbil dead my other gerbil was eating it i just cried and screamed"
    http://www.livescripts.net

    --------------------------------------------------------------------------------
    Last edited by some moderator : Today at 9:01 PM.

  13. #13
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Turns out pre-calculating the trigonometry makes it slower rather than faster. :/
    http://www.birchlabs.co.uk/
    You know you want to.

  14. #14
    Senior Member axcho's Avatar
    Join Date
    Jun 2006
    Posts
    113
    Nice! Do you have a link to iopred's engine? I would like to do cool particle effects too.

  15. #15
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    http://www.birchlabs.co.uk/
    You know you want to.

  16. #16
    Senior Member axcho's Avatar
    Join Date
    Jun 2006
    Posts
    113
    Thanks! I'll take a look at it.

  17. #17
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    I bitmap-cached the static parts of the castle, and got rid of the collision bitmap I wasn't using (note how the Redraw Regions are no longer the entire screen now). This bumped the framerate up about 2-4 fps!
    Last edited by VENGEANCE MX; 11-11-2006 at 08:40 PM.
    http://www.birchlabs.co.uk/
    You know you want to.

  18. #18
    Senior Member
    Join Date
    Jun 2001
    Posts
    290
    Quote Originally Posted by VENGEANCE MX
    Use flipflopping for collision detection.....
    can you explain that a bit?.....I think I heard of that before, but can't remember....thanks!


    paul.

  19. #19
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    Slightly varying FPS from 31.2 to 30.4. Amazing.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  20. #20
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Flipflopping is where you halve the number of collision checks you have to do by only checking half of the collisions on each frame. Like so:

    PHP Code:
    flipFlop true;
    collision = function() {
    flipFlopStart flipFlop;
    for (var 
    i in enemies) {
    flipFlop = !flipFlop;
    enemies[i];
    if (
    flipFlop) {
    // Check for collision
    }
    }
    flipFlop = !flipFlopStart;
    };
    onEnterFrame collision
    Or something along the lines of that. I may have made a mistake or two, but that's the general idea of how to go about skipping every second troop (another way to do it is to check all the collisions every two frames instead of half the collisions every frame, but the latter way spreads the processor load more evenly).

    Also, something interesting: It was faster for me to attachBitmap() on the same depth rather than use attachBitmap() and scrollRect() when I was trying to change the frames the arrows were on. It might be something to do with how big my arrow sprite sheet was: http://www.birchlabs.co.uk/ArrowSpriteSheet.png :/
    http://www.birchlabs.co.uk/
    You know you want to.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center