`
java-mans
  • 浏览: 11413746 次
文章分类
社区版块
存档分类
最新评论

Understanding pixel format in cocos2d v0.7.3

 
阅读更多

转载自:http://www.cocos2d-iphone.org/archives/61

Since cocos2d v0.7.3, you can specify the texture’spixel formatof your PNG/TIFF/BMP/GIF images.
The texture’spixel formatis the way the image is stored in GPU memory.

Possible pixel formats:

  • RGBA8888 (32-bit)(kTexture2DPixelFormat_RGBA8888)
  • RGBA4444 (16-bit)(kTexture2DPixelFormat_RGBA4444)
  • RGB5_A1 (16-bit)(kTexture2DPixelFormat_RGB5A1)
  • RGB565 (16-bit)(kTexture2DPixelFormat_RGB565)

RGBA8888:

  • 8bits are assigned to theredchannel,8bits to thegreenchannel,8bits to thebluechannel and8bits to thealphachannel.
  • Use this pixel format when you need themaximum possible qualityfor your image.
  • But it will consume the double of memory compared to 16-bit textures. Memory is a precious resource on the iPhone
  • Usually it is also slower to render.
  • Useful for: background image of your intro scene, and for images with lots of gradient colors

RGBA4444:

  • 4bits are assigned to theredchannel,4bits to thegreenchannel,4bits to thebluechannel, and4bits to thealphachannel
  • It gives you good quality in all channels, good speed, good memory consumption.
  • Useful for:spritesthat have different values of transparency

RGB5A1:

  • 5bits are assigned to theredchannel,5bits to thegreenchannel,5bits to thebluechannel, andonly1bit to thealphachannel
  • It gives you good quality in RGB channels but poor quality on the A channel. It also gives you good speed and good memory consumption.
  • Useful for:spritesthat have transparent parts, but the transparency is either On or Off

RGB565:

  • 5bits are assigned to theredchannel,6bits to thegreenchannel, and5bits to thebluechannel. It hasno alphachannel support
  • It gives you thebest possible quality for 16-bittextures, butwithout alphachannel support.
  • Useful for: background images in your game.

The default pixel format in v0.7.3 is RGBA8888.

How to use it:


FAQ:

  • Q:Can I use this technique for PVRTC images ?
  • A:No, PVRTC images have their own format. PVRTC images are faster and they consume less memory since they are either 2-bit or 4-bit textures but the quality is not that great.
  • Q:If I use 16-bit textures, will my game load faster ?
  • A:The texture pixel format has nothing to do with the loading times of your game. The Pixel Format is how the image is stored in the GPU memory. If you want faster loading times you should reduce the size of your .PNG/GIF/TIFF/TMP image file.
  • Q:Should I use RGB565 for the images that are compressed by XCode ?
  • A:When XCode compresses the PNG images, it will create a compressed PNG image that has it’s alpha channel premultiplied in the RGB channels. The PNG format is RGB565, but you should NOT confuse a PNG format with a texture pixel format. A PNG image is understood by Photoshop and cocos2d, but the GPU knows nothing about PNG images. The PNG images need to be converted into a Texture (the format understood by the GPU). The answer is: it depends on what you want. The Image (PNG,GIF,TIFF,BMP) format is independent of the Texture format.
  • Q:If I create a PNG/BMP/TIFF/GIF image without alpha channel, can I change the texture pixel format ?
  • A:If your PNG/BMP/TIFF/GIF image has no alpha channel (premultiplied or not), then the pixel format that will be used for the texture is RGB565. It can’t be changed using the API but you can change by modifying the Texture2D.m file
  • Q:Can I change the pixel format once the texture was created.
  • A:No. Once the Texture was created you can’t modify the pixel format. But you can create new textures from the same image using different pixel formats.Just remember to remove the image from the TextureMgr!

分享到:
评论

相关推荐

    Cocos2d-x实战:JS卷——Cocos2d-JS开发

    资源名称:Cocos2d-x实战:JS卷——Cocos2d-JS开发内容简介:本书是介绍Cocos2d-x游戏编程和开发技术书籍,介绍了使用Cocos2d-JS中核心类、瓦片地图、物理引擎、音乐音效、数据持久化、网络通信、性能优化、多平台...

    cocos2d入门cocos2d入门

    cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门 cocos2d入门

    cocos2d-x json字符串与cocos2d::Value转换工具

    该资源主要用于cocos2d-x中Value与json字符串的相互转换,提供从json文件读取为cocos2d::Value,cocos2d::Value写入到文件,cocos2d::Value转换为json字符串,json字符串转换为cocos2d::Value。json字符串转换成cocos...

    cocos2d-x-2.1.5

    cocos2d-x-2.1.5

    Cocos2D权威指南

    第1章 开始前的准备工作 1 第2章 你的第一款iPhone游戏:垂直射击游戏 38 第3章 Cocos2D核心类 69 第4章 Cocos2D中的动作、特效与动画 152 第5章 Cocos2D中的文本渲染系统 229 共19章

    cocos2d-x事件类

    在使用cocos2d-x开发游戏的过程中,为了实现逻辑和显示相分离。 在下通宵了一个晚上,写出了该事件类。 谨记,该事件只能用于cocos2d-x中。 事件发送者需要继承EventDispatcher类 事件接收者需要继承EventHandle类...

    cocos2d初级教程-Cocos2d SimpleGame源码

    Ray Wenderlich的《Cocos2d SimpleGame》,被认为是cocos2d的初学者最好的教程,这本书被Cocos2D-X团队从objective-c转化到了c++版,并发布在了github上。在此感谢Ray Wenderlich的慷慨相助。 源代码是在cocos2d-x ...

    cocos2d-x游戏代码

    cocos2d-x游戏代码

    Cocos2d-x高级开发教程

    Cocos2d-x是移动跨平台开发最流行的游戏引擎,而本书是一本很全面的、比较‘接地气’的游戏开发教程。书中汇聚了热门手机游戏《捕鱼达人》开发的实战经验,作者从最基础的内容开始,逐步深入地介绍了Cocos2d-x的相关...

    cocos2d-android jar包全套.zip

    如果你想用cocos2d开发android游戏,但是又不方便找包,这里就可以为你提供cocos2d开发的所有相关包,解压后得到libs文件夹即可。

    Cocos2d-x实战 JS卷 Cocos2d-JS开发

    Cocos2d-x实战 JS卷 Cocos2d-JS开发 PDF 电子书完整版本

    教你用Cocos2D-X开发跨平台移动应用

    Cocos2d-x源于Cocos2d,是一款开源游戏引擎项目,是一款基于对原有iOS平台cocos2d重写为C++的开源代码,封装了OpenGL,Box2d,LibCurl,LibPng等开源的跨平台代码。由于基于C++和STL特点使其广泛应用于游戏开发、移动...

    Cocos2d-html5

    Cocos2d-html5

    cocos2d的学习资料

    cocos2d的学习资料,一本比较经典的cocos2d开发书,适合cocos2d/cocos2d-x的入门

    cocos2d-x_v3.16安装及环境变量配置文档

    ocos2d-x v3.16 安装流程文档 ocos2d-x v3.16 环境变量配置文档

    大富翁手机游戏开发实战基于Cocos2d-x3.2引擎

    资源名称:大富翁手机游戏开发实战基于Cocos2d-x3.2引擎内容简介:李德国编著的《大富翁手机游戏开发实战(基于 Cocos2d-x3.2引擎)》使用Cocos2d-x游戏引擎技术,带领读者一步一步从零开始进行大富翁移动游戏的开发...

    Cocos2d-x实战 JS卷

    Cocos2d-x实战

    cocos2d-x实战项目

    cocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML文件读取与骨骼动画.rarcocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML...

    cocos2d粒子编辑器 particle_builder -windows

    windows环境,一款很好用cocos2d粒子特效编辑器,里面有不少例子

    cocos2d-x游戏实例-纵版射击游戏(cocos2d-x 2.0.4)

    本人提交源码进行了版本移植并修改了一个bug,目前使用VS2008+cocos2d-x,2.0.4版本编译测试过(需要注意的是,我的IDE环境中是将COCOS2d-x的头文件和库文件设置到了VS环境中对所有项目生效,并没有单独对特定的COCOS...

Global site tag (gtag.js) - Google Analytics