Can someone explain the whole "Power of Two"?

sewinstonsewinston Member Posts: 51
edited November -1 in Working with GS (Mac)
I know that computers like numbers like 8, 16, 32, 64, 128, 256, etc. I'm going to assume that the iphone was optimized to use image files of these pixel dimensions. My questions are:

1- Is the performance decrease significant? Is there a difference in the decrease between something small like 130px instead of 128px vs. something big like 340px vs 256px?

2- Does it have to be square? For example can I do 128x64 and it still be optimized?

3- is it just 8, 16, 32, 64, 128, 256, etc. or can you use half steps like 12, 24, 97, 192, etc.

Thanks.

Comments

  • butterbeanbutterbean Member Posts: 4,315
    I don't know much about the significance of performance, but I know that in regards to #2 question, you can do 128X64 and mix and match the power of 2 numbers, but you shouldn't do half steps like 12, 24 etc... You could do that, but I think for optimization, it's best to try to always stick to the power of 2 rule

    I've broken that rule a few times, so we'll see how much of a deterent it is to optimization in gameplay....
  • ktfrightktfright Member Posts: 964
    Basically, it is like if I had an image like 256x512, I'm not wasting any space, but if I had something like 257x513, I'm actually using 512x1024, wasting a lot of space. If youre over the power of 2 numbers, it doubles to the next PO2 number on the list.
  • sewinstonsewinston Member Posts: 51
    Got it, thanks guys.
  • xactoxacto Member Posts: 146
    Question here....

    So with the Display Size set at 480x320, by making a graphic that is 480 in width would waste space?

    Example: I have a star field set at 480x1500 that scrolls. What would be the best for the power of 2?
  • CobraCobra Member Posts: 160
    Keep in mind that using power of 2 dimensions for your images is not a requirement. It's just good to know how much memory your images are really taking up, so you can make practical optimization decisions.

    Let's use Xacto's 480x1500 star field image as an example:

    - This image takes up the same amount of memory as a 512x2048 image.

    - So, the width could go up to 512 without using any additional memory. Would that be useful? Probably not.

    - The height could go up to 2048 without using any additional memory. That could be nice to take advantage of, since the image will scroll vertically. (BUT this should actually be implemented as two 1024-height images if it's an iPhone project.)

    - Let's say Xacto wants to trim this image to improve performance. Reducing the height to 1200, or 1100, or even 1025 would have no effect. Reducing the height to 1024 would have a significant effect -- all other things being equal, it would take up half as much memory.
  • quantumsheepquantumsheep Member Posts: 8,188
    if it scrolls, I'd make it 512x512

    I got away with 512x256 with my side scroller as the HUD took up some space.

    All in the name of optimisation! ;)

    Edit: Why is its length 1500 - could you not make it repeat itself and have it smaller?

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • JGary321JGary321 Member Posts: 1,246
    hey tshirtbooth,

    If your game is not action-intensive, it won't really matter. If it doesn't have a lot of moving actors it probably won't matter. A game like mine has a lot of actors moving on screen, so I have to keep as much memory as possible.

    My map images & BG's are all 480 x 320. But this means that the iPhone is really computing it as an image of 512 x 512 (memory wise). Since this is only one actor no big deal. But if I had 20 actors on screen that were that size & all moving..... I think you see the point. It would be a lot of waste. So in essence, no matter the size of your graphic file (not actor) the system will use memory based on a picture of the size of: 8, 16, 32, 64, 128, 256, 512, or 1028.

    Hope this helps.

    PS. Personally I would leave your pictures the same.
  • quantumsheepquantumsheep Member Posts: 8,188
    "then 10 actors spawn during the scene to show you that you got points and to show you where you touch and none of them are to the power of 2"

    Start here!

    QS :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • JGary321JGary321 Member Posts: 1,246
    I emailed a Moderator a while back & confirmed that ACTOR SIZE does not follow power of 2. Only the original image. So you are fine there. As for why u get a crash no idea. =(
  • JGary321JGary321 Member Posts: 1,246
    Also here's a visual. To show the waste the first part is the size of a dimension. The second after the = is what the computer sees. In other words a picture's "alphabet" might have 1,028 numbers in it. The CPU "alphabet" has 8 numbers. (Just giving an example)

    1 - 8 = 8
    9 - 16 = 16
    17 - 32 = 32
    33 - 64 = 64
    65 - 128 = 128
    129 - 256 = 256
    257 - 512 = 512
    513 - 1028 = 1028

    Larger images are not supported on the iPhone.
  • ktfrightktfright Member Posts: 964
    i got a question: how can i make my image smaller in a program without making it lose its quality, because my actor is 16x32, but when i make the image that same size, it looks blurry, but when i make it its original size, which is like 397x641, it looks better, but i know its a memory leak in there somewhere. i currently can't test until i get my financial aide, but i hope you understand what i mean.
  • JGary321JGary321 Member Posts: 1,246
    There IS going to be a loss of quality. No way around that. Vector images can be resized without any loss, but normal bitmap cannot.
  • ktfrightktfright Member Posts: 964
    Then what can I do to convert the image to vector instead of bitmap?
  • SDMGSDMG Member Posts: 280
    hi ktfright,

    you can't use vector-images in GS.

    I don't know which ImageEditor you are using, but for example in Photoshop you can choose one of 3 or 4 methods how Photoshop scales images down.
    Depending on your choice your bitmap could look more or less blurry.

    and just another Idea... maybee you can try the following too:

    When your image with dimension 397x641 looks sharp on an actor with 16x32 pixels... try to make a screenshot in GS, crop your image in an ImageEditor to 16x32 and use this image for your actor... (don't know if this works ;)

    Otherwise like mentioned above i would have a look into my ImageEditor and search for a way to choose a sharper scaling method...

    ...oh and now when i am ready writing this i remember that your brother has the adobe suite? ;) or am i wrong ? so in the preferences of photoshop you find the scaling methods... this could help...

    cheers

    SDMG
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Also make sure your images are 72dpi. Not 72.01dpi like some programs like to make them.
  • JGary321JGary321 Member Posts: 1,246
    Here is the underlying problem with converted a 397x641 to 16x32. This is only an example these numbers are not accurate. Just meant to show why there is loss of quality. Lets say 397x641 is actually the number of pixels. That would be the image has 397 x 641 pixels for alot of different colors, therefore it can show lots of detail. But when you convert it to 16x32 it only has 16x32 pixel of color to try & emulate that detail. NOT gonna work. The more you convert the image down the more quality is lost.

    I would try making your image 32x64. See if that makes a difference. If there isn't a lot of action going on in the scene you may be able to just take the hit & make it keep higher dimensions. Up to you to know if you can afford the memory. For instance, I had some 'icons' in my game that were like 120x150 or something. I kept them & made my actor in game 40 x 40. Because on that scene there was no action, no moving parts, it was basically a stat/skill/character screen. So it worked for me there.

    Hope this helps.
Sign In or Register to comment.