User Tag List

Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 31

Thread: Guide to faster games with less memory usage

  1. #1
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, ┼rhus
    Posts
    3,455
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Guide to faster games with less memory usage

    I see many cool games being developed around here for the iPhone. Many of them are designed with a PC in mind which can lead to problems on the iPhone as it is still only a mobile device with very limited capabilities. The iPhone has very limited RAM and will quickly begin to send out low memory warnings to all running applications.

    So I thought I wanted to write out a little guide for you to make your games:
    - load faster
    - run faster
    - consume less battery power
    - take less disk space
    - use less memory on the device

    Best optimization tip:
    Use the 'Color reduction' option globally


    Pitfalls

    Alpha-channels
    Alpha-channels look awesome and gives a visually pleasing effect but they will slow down your game if you overuse them, just as they do in the PC runtime (just more).

    An image with an alpha-channel takes 33% more memory and space than an image without + it takes more power and time to render them.

    Workaround:
    Does your graphic really need the alpha-channel? Does the background underneath it ever change? If not you could probably "bake" the alpha-channel effect into the image itself so that the shadow is just part of the picture.

    Huge pictures
    Many are often tempted to import really large pictures into the game where it will only show very little of that picture at one time. A good advice is to break it up into smaller parts so that fewer of them are shown at one time.

    Remember that any image you have in your game has to fit inside their own texture. In a sample game I saw there was a 960x480 sized background image on a frame. This picture alone had to fit into a 1024x512 texture taking up a huge amount of memory. What was even worse was that it had an alpha-channel even though no pixel in it was transparent. Second, the same frame had two different huge animations sized 957x158 (each of them contained 17 frames). This already takes up 2*17 * 1024*256 * 3 = 26738688 bytes = 25.5 MB of RAM which is way above what the iPhone likes. That was even without the rest of the graphics and the huge background image I talked about before.

    Workaround:
    Most graphics doesn't need 100% crispness and quality. It will only take 1/4th of the previous memory usage if you cut your image size in half and then at runtime scale it to 2.0. It will also run much faster as it utilizes the graphics card RAM cache much better.

    Tip: (From Yves)
    Crop your images, remove any useless empty space around them. Some developers tend to use a single frame size for an entire animation with sometimes huge transparent parts in some images. It's probably better at design time, but at runtime it results in a loss of time and space.

    Tip:
    Try to make your graphics of a size close to something of a power-of-two. It will waste less precious memory.
    A power of two size is one of the following: 8,16,32,64,128,256,512,1024
    Images less than 8x8 pixels will be stored in a 8x8 texture as they cannot be smaller than that.
    You can easily use different sizes for your width and height, they don't have to be equal.

    Tip:
    Be sure to set the "Image compression" property to "Color reduction" either globally for all objects in the App iPhone properties or per object - as often as you can.
    In many cases it will make it consume half the memory it did before.
    Take for example the big background image before:
    Before it wasted 2 MB of texture memory.
    With color compression and no alpha channel it will only take 1 MB. And if it was cropped to only fill out the resolution of the iPhone device it would only take 30 KB.
    The animations mentioned before that took 25 MB of RAM can with color compression and half the resolution only take: 2*17 * 512*128 * 2 = 4456448 bytes = 4.25 MB!
    That is a huge difference.


    Single color graphic
    This is kinda an extension to the previous pitfall:
    I have also often in the sample games I've debugged seen some big actives (typical white) that are meant to cover the entire screen and fade to transparent. People need to realize that even thought they are pure white (or whatever color) they are still stored in memory uncompressed at runtime and waste just as much memory as if it was a pretty picture. If you need those fade-effects you can again scale a small active to fit the screen at runtime and gradually alter it's semi-transparency.


    Transitions on big graphics
    You should in general avoid using transitions on objects larger than the iPhone screen resolution even though it works well enough. Using a transition on such an object will consume a lot of extra memory during the transition and can be slow. You have to try it at runtime to see if it gives you a noticeable performance drop. Just remember that even though it doesn't hurt the FPS that much, it can still drain the battery much more than you know.


    Overuse of "text" counters/score and strings
    Though it may not be a big of a performance issue, it can hurt your game's performance a little bit if you use too many objects that draws text. If the text doesn't change it should not be a performance problem, but if you update your string/score/counters often (as counters/scores often do) you will get a performance problem.

    Workaround:
    Only use text whenever you know it will not change often (like every frame).

    Use bitmap counters/scores instead of text counters/scores. There you can also much better control the visual style of your objects and there is nearly no performance penalty.


    Too many transitions at one time
    Each object that needs to have a transition effect on it will consume more memory than usual and will use some special buffers on the device that aren't unlimited. Once you reach a certain limit you will begin getting errors.

    Also if you have many transitions going on at one time it will slow down performance.

    Note: Some transitions are slower than others as they aren't generally suited for hardware acceleration (effects that does many small pixel effects). Try out the performance of them and find one that suits your purposes and runs fast enough.

    Workaround:
    Instead of using transitions try using animations or other effects to give the same effect.

    Instead of using the "Fade" transition, manually setting the semi transparency of your objects will be much much faster and will not consume any more memory.


    Unnecessary Ink-effects
    I have seen other games almost ready for release where INK effects are unnecessarily used very often.
    Instead of having a big background covering the screen and setting it to either transparent or ADD so that it will be added to some gradient behind it, it will only make your game slower and consume more power. Instead, make your graphics as they should look at runtime and then use them like that. INK-effects are only meant for places where you cannot modify the original image to look like it should at edit time.
    For example if you want a grayscale background from a picture, you make it grayscale before you import it into MMF2. You simply don't put the monochrome INK-effect on it and forget about it

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleMac Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Koji_Kabuto's Avatar
    Join Date
    Jul 2006
    Location
    Venezuela
    Posts
    2,851
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Guide to faster games with less memory usage

    Thanks Andos, excelent guide...

    Remember IPhone is not a PC....

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperiOS Export ModuleSWF Export ModuleMac Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    JasonDarby's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    4,925
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Re: Guide to faster games with less memory usage

    Excellent guide Andos, great starting point

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperiOS Export ModuleSWF Export ModuleMac Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    JasonDarby's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    4,925
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Re: Guide to faster games with less memory usage

    Some if not all of that should be put into the docs and Jeff's FAQ guide... its really useful stuff.

    You said to me on chat about making the image smaller and then resizing, so just using the resize option in the events right? Should add that to your guide.

  5. #5
    Clickteam Clickteam
    Anders's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, ┼rhus
    Posts
    3,455
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Guide to faster games with less memory usage

    It is already mentioned under the workaround for huge images

  6. #6
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperiOS Export ModuleSWF Export ModuleMac Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    JasonDarby's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    4,925
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Re: Guide to faster games with less memory usage

    Ah yeah well it was late when i read it

    Cool stuff though.

  7. #7
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    13,190
    Mentioned
    141 Post(s)
    Tagged
    2 Thread(s)

    Re: Guide to faster games with less memory usage

    Another (obvious) tip : crop your images, remove any useless empty space around them. Some developers tend to use a single frame size for an entire animation with sometimes huge transparent parts in some images. It's probably better at design time, but at runtime it results in a loss of time and space.

  8. #8
    Clicker Fusion 2.5 DeveloperFusion 2.5 DeveloperiOS Export ModuleSWF Export ModuleMac Export ModuleUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    JasonDarby's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    4,925
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Re: Guide to faster games with less memory usage

    Yeah, thats a good tip to add, (me has quite a few images that need cropping)..

    My problem with cropping is that if an image is moving within the transparent area, its difficult to crop without causing issues to the animation... is there any recommendations for how to fix that efficiently (not really part of iphone) but something that i would like to know.

    Jason

  9. #9
    Clickteam Clickteam

    Join Date
    Jun 2006
    Location
    France
    Posts
    13,190
    Mentioned
    141 Post(s)
    Tagged
    2 Thread(s)

    Re: Guide to faster games with less memory usage

    What do you mean Jason? When you crop an image, the hot spot position is automatically adjusted, it shouldn't cause any issue?

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleMac Export ModuleUnicode Add-on
    Pharanygitis's Avatar
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    1,037
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Guide to faster games with less memory usage

    Very nice Thank you !

Page 1 of 4 1 2 3 ... LastLast

Similar Threads

  1. Guide to faster games with less memory usage
    By Anders in forum iOS Export Module Version 2.0
    Replies: 104
    Last Post: 6th December 2013, 07:23 PM
  2. Confirming the memory usage
    By ASD in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 2nd January 2010, 08:48 PM
  3. MMF2 Memory Usage
    By Cossin in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 28th July 2008, 08:20 AM
  4. Memory usage: objects needs how much?
    By Leander in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 26th July 2008, 11:44 PM
  5. SQLDB memory usage (bug?)
    By Kunci in forum Extension Development
    Replies: 0
    Last Post: 10th October 2007, 01:42 PM

Posting Permissions

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