User Tag List

Results 1 to 10 of 10

Thread: Using Lots of Objects Optimally?

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using Lots of Objects Optimally?

    I'm working on a platformer, and up until this point everything has run smoothly. I do have 10 layers, which 8 of them are at different parallax rates, mainly to test how far I can push it right now. The resolution of the game is 800x450, and the stage size is 45000x2000. All the layers besides the main one have repeating quick backdrops with transparency. There's lots of platform active objects the character interacts with on the stage. With all of that, nothing has caused any slowdown. But once I added lots of little pick up items, just active objects 16x16 in size, solid color, that are destroyed upon collision and add points to score, the game slowed to a crawl. If I destroy these objects on start of frame, the game runs smoothly. I tried reducing the backdrop objects, and have them not repeat at all, didn't help. Lowering colors from 16 million to 65536 didn't help. So I'm left to believe it's the amount of objects. When running, it says 2750 objects, 198 mb.

    Any help would be appreciated! I'm pretty ignorant about optimization in general, although I have looked through some tutorials on here and haven't found anything that seems to address this particular issue. Thanks!

  2. #2
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    the best ways I think would be:

    -deactivate all off-screen objects, exempting them from any code or checks
    -create objects on the fly when you get near them, using an array system

    Most games, especially older games use the second method. They make everything in a level editor, then load it on the fly. There are two ways you can think about doing that, too:

    -create whole rooms at a time
    -create rows of tiles at a time and move the world around the player

    There are a few examples of these methods on the forums, i think. I know solarB has one and i'm pretty sure there were others...

    http://community.clickteam.com/threads/93817-Array-of-actives-for-a-scrolling-level
    http://community.clickteam.com/threads/90401-Tutorial-How-to-Make-a-Level-Editor
    http://community.clickteam.com/threads/90009-Unlimited-Open-World-Platformer?highlight=unlimited+open+world

    Using the editor method is quite a big jump if you aren't prepared, though. You can most likely see a big improvement just from deactivating off-screen objects. Forcing "Load on Call" for all objects can net you some performance gains, as well.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool, thanks for the suggestions! I actually bookmarked the video series on the level editor a few months back, guess it's time to sit down and try to learn it.

    As far as deactivating all off-screen objects, how would I go about doing that? Sorry if that's something simple, I haven't done it before. Thanks!

  4. #4
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Always get the object's distance to the center of the window, and if it is greater than a certain amount, set a flag off. If it's lower or equal than that amount, set the flag back on. Then only do calculations on or move objects that have their flags ON by checking for it in your conditions. Use an object alterable value to store the distance, using the distance() function.

    To get the center of the screen, you would use

    x center:
    -(x left frame + x right frame)/2

    y center:
    -(y top frame + y bottom frame)/2

    So you would have an always event like so:

    Always
    -set object alterable value 'Distance from screen' to Distance( X ("object"), Y ("object"), (x left frame + x right frame)/2, (y top frame + y bottom frame)/2)

    After that, you set the flag:
    'Distance from screen' of object > YOUR VALUE
    -set object flag OFF

    'Distance from screen' of object <= YOUR VALUE
    -set object flag ON

    Make sure this is above your other object events, so the distance of each object and the flag is refreshed to the latest values before you do any checks.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, thanks so much! It's about time I start properly doing this stuff. This is really helpful.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had an idea, and maybe this won't work, but I'm wondering what you think. Is there a way to start the level, log the positions of every instance of an object, delete all the objects, and then create them on the fly using the recorded information? I'm thinking this might be a good compromise to going the whole level editor route, which after watching and following along with several of the videos, I really don't know if I'd be able to successfully implement.

  7. #7
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    That should be possible using an Array. With a large amount of objects though, writing them all to Array at the start will cause a few seconds of hanging. You might want to use a type of level editor solely for your objects: a sort of "edit mode" that you can enter and use to place them in your level. This lets you populate the array one at a time instead of all at once. Once you're done with edit mode, you would save that array to a file, and load it at the start of actual gameplay. Then you'd use some loops or something to check the array for objects as you go along.

    Honestly though, if you want my advice: it is very worth learning level editors. Very large frames with many objects don't work well at all in fusion. You can hack some things together, but in the end a level editor will always be both more efficient and easier to work with (if you make one right). Either way you choose, good luck with your projects

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, cool, I'll definitely keep trying at it. Thanks so much for the help!

  9. #9
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    824
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by casleziro View Post
    Always get the object's distance to the center of the window, and if it is greater than a certain amount, set a flag off. If it's lower or equal than that amount, set the flag back on. Then only do calculations on or move objects that have their flags ON by checking for it in your conditions. Use an object alterable value to store the distance, using the distance() function.

    To get the center of the screen, you would use

    x center:
    -(x left frame + x right frame)/2

    y center:
    -(y top frame + y bottom frame)/2

    So you would have an always event like so:

    Always
    -set object alterable value 'Distance from screen' to Distance( X ("object"), Y ("object"), (x left frame + x right frame)/2, (y top frame + y bottom frame)/2)

    After that, you set the flag:
    'Distance from screen' of object > YOUR VALUE
    -set object flag OFF

    'Distance from screen' of object <= YOUR VALUE
    -set object flag ON

    Make sure this is above your other object events, so the distance of each object and the flag is refreshed to the latest values before you do any checks.

    This is one way to deactivate offscreen objects, but you might not want do a distance calculation if you can help it. Doing a distance calculation for every single object could burden the CPU as square roots require more cycles than addition/multiplication/comparison/etc. Besides, there's a simpler way:

    Always ---> Set object flag OFF

    X("Active") > X left frame - 100
    +X("Active") < X right frame + 100
    +Y("Active") > Y top frame - 100
    + Y("Active") < Y bottom frame + 100
    ----> Set object flag ON



    Alternatively, if you still want to use distance, use the square of the distance instead. In other words, instead of doing:

    sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) > YOUR VALUE

    square both side of the equation and do:

    (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) > YOUR VALUE * YOUR VALUE

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)Universal Windows Platform Export Module (Steam)
    joegp's Avatar
    Join Date
    Jan 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, OK, cool, thanks!

Similar Threads

  1. Lots Of Questions about
    By flyoffacliff in forum SWF/Flash Export Module Version 2.0
    Replies: 10
    Last Post: 30th April 2013, 11:51 AM
  2. Lots o crashes
    By SirEatAlot in forum Android Export Module Version 2.0
    Replies: 11
    Last Post: 20th September 2012, 11:18 PM
  3. Lots of objects with lots of counters set to their positions...
    By ratty in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 14th July 2012, 01:45 PM
  4. Save lots of objects with INI or Array
    By devripper in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 9th March 2012, 12:08 AM
  5. Ordering lots of backdrop objects problem...
    By mobichan in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 18th May 2009, 06:35 AM

Posting Permissions

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