Texture Dimensions
Texture mapping is a standard technique used to display images in iOS games and apps. In iOS devices, textures are constrained to dimensions with a power of two. In other words, the width or the height of a texture can only be in terms of 2, 4, 8, 16, 32, 64, 128, 256, 512 or 1024 (pixels). From iOS 4 onwards, textures can be as wide or as high as 2048 pixels.
A texture comes into play when we create a sprite from an image file. For example, we use the cocos2d CCSprite class to instantiate a sprite in a game using an image file:-
CCSprite *target = [CCSprite spriteWithFile:@"Target.png" rect:CGRectMake(0, 0, 27, 40)];
If Target.png in the above example is 260 x 260 pixels in dimension with 32-bit colors, it should in theory use only 270 KB. But if we attempt this in iOS, we will discover that it actually uses 1 MB!
This unexpected increase is due to the constraint that texture need to be powers of 2 in its width and its height. iOS has created the next best texture of 512 x 512 (since 260 x 260 just missed 256 x 256 by 4 pixels in each attribute) and this uses 1 MB of memory.
The simple solution is to create image files that takes the powers-of-two rule into account. Taking care of this little detail goes a long way towards solving memory and performance related issues when rendering images in your iOS game or app.