Game Development Reference
In-Depth Information
for the HD texture. The SD texture will be about 512×512 pixels in size and consume a
quarter of the memory, which is 512KB. Note that the SD texture atlas may not always
be exactly half the width and height of the HD atlas. That's because some layout fea-
tures such as padding don't scale when the SD texture is created.
Caution Unless you develop your game exclusively for the latest generation of
devices, you shouldn't use a texture width or height above 2048 pixels. All
devices supported by cocos2d 2.0 support texture dimensions of 2048×2048
pixels—only iPhone 4S and iPad 2 and newer support 4096×4096 texture di-
mensions. You can limit the maximum texture size that TexturePacker should
generate in the left-hand pane's Geometry section.
TexturePacker uses several tricks to optimize the texture space to create an optimal
packing rate. First it trims the transparent border pixels of each image. Cocos2d com-
pensates for this by adding the trimmed area as an offset to the sprite's position when
drawing it. This has two advantages: it reduces the texture size and speeds up the ren-
dering of the sprites.
You may also notice that some images are rotated. TexurePacker rotates them to optim-
ize how the texture atlas space is used. Again, cocos2d compensates by restoring the
original orientation when loading the image into memory. If you add two or more ex-
actly identical images, TexturePacker will add only one image to further save texture
atlas space. If the images are referenced by different filenames, then you can load the
image in cocos2d by using any of the image's source filenames. Whenever an image in
a texture atlas has multiple source files containing the same image, TexturePacker will
draw a small overlay (a stack of paper) over the image in the center pane.
In case you're wondering about the Border Padding and Shape Padding settings, they
determine how many pixels of space are left between all images and the border of the
atlas. The default of 2 pixels ensures that all the images in the texture atlas can be
drawn without any artifacts. With less padding, images can show stray pixels around
their borders when displayed in your game. The amount and color of these stray pixels
depend on the surrounding pixels from other images in the texture atlas. This is a tech-
nical issue that has to do with how the graphics hardware filters textures, and the only
solution is to leave a certain amount of padding between all images in a texture atlas.
Search Nedrilad ::

Custom Search