原文貌似被墙: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:
// Set the pixel format before loading the image
// RGBA 8888 image (32-bit
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
Sprite *sprite1 = [Sprite spriteWithFile:@"test-rgba1.png"];
// Set the pixel format before loading the image
// RGBA 4444 image (16-bit)
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444];
Sprite *sprite2 = [Sprite spriteWithFile:@"test-rgba2.png"];
// Set the pixel format before loading the image
// RGB5A1 image (16-bit)
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGB5A1];
Sprite *sprite3 = [Sprite spriteWithFile:@"test-rgba3.png"];
// Set the pixel format before loading the image
// RGB565 image (16-bit)
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGB565];
Sprite *sprite4 = [Sprite spriteWithFile:@"test-rgba4.png"];
// restore the default pixel format
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_Default];
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游戏编程和开发技术书籍,介绍了使用Cocos2d-JS中核心类、瓦片地图、物理引擎、音乐音效、数据持久化、网络通信、性能优化、多平台...
这个压缩包“cocos2d-x-cocos2d-x-2.2.2.zip”包含了cocos2d-x 的2.2.2版本,该版本是cocos2d-x发展中的一个重要里程碑,它提供了许多改进和优化,使得开发者能够更加高效地创建2D游戏和应用。 在cocos2d-x 2.2.2中...
Cocos2d是一款开源的游戏开发框架,被广泛用于创建2D游戏、演示程序和其他互动内容。在Android平台上,Cocos2d-x是一个基于C++的版本,提供了原生的编程接口,同时也支持Java API,方便Android开发者使用。"cocos2d-...
cocos2d-android游戏引擎是著名游戏引擎cocos2d游戏引擎的Android版。cocos2d-android游戏引擎性能优越、易学、可以进行纯java编程、具有极高的研 究价值、大大的降低了开发者的学习成本。您只需要一台普通配置的...
《Cocos2d-x实战 JS卷 Cocos2d-JS开发》是一本深入探讨Cocos2d-x游戏引擎JavaScript版本使用的专业书籍。Cocos2d-x是全球范围内广泛采用的游戏开发框架,尤其适用于2D游戏的制作,而Cocos2d-JS则是其JavaScript接口...
【cocos2d-x API中文文档】是一份详尽的资料,主要涵盖了cocos2d-x游戏引擎的API,这份文档适用于2015年的最新版本。cocos2d-x是一个基于MIT许可证的开源游戏引擎,它以快速、简单且功能强大的特性闻名,允许开发者...
该资源主要用于cocos2d-x中Value与json字符串的相互转换,提供从json文件读取为cocos2d::Value,cocos2d::Value写入到文件,cocos2d::Value转换为json字符串,json字符串转换为cocos2d::Value。json字符串转换成cocos...
《cocos2d-x 3.0:游戏开发中的角色移动技术详解》 在游戏开发领域,cocos2d-x是一款广泛使用的开源2D游戏引擎,尤其在移动平台上的应用非常广泛。cocos2d-x 3.0版本带来了许多性能优化和新特性,使得开发者能够更...
cocos2d-x 是一个开源的游戏开发框架,使用 C++ 语言编写,支持多平台发布,包括 iOS、Android、Windows、macOS、Linux 和 Web。cocos2d-x v3.16 是该框架的一个版本号,本文档主要介绍了该版本的安装流程以及环境...
《cocos2d-x 3.8:经典游戏引擎源码解析》 cocos2d-x 是一个跨平台的游戏开发框架,它基于C++,同时提供了Lua和JavaScript的绑定,让开发者可以方便地在多种操作系统上创建2D游戏、演示程序和其他图形交互应用。这...
"cocos2d-x windows vs2010 配置详解" 本文将详细介绍如何在 Windows 环境下使用 Visual Studio 2010 配置 Cocos2d-x 游戏引擎。Cocos2d-x 是一个跨平台的游戏引擎,可以在多种平台上运行,包括 Windows、Mac OS X...
《Cocos2d-x实战:C++卷(2版)源代码》这本书是关于使用Cocos2d-x游戏引擎进行游戏开发的专业指南。Cocos2d-x是一个开源的、跨平台的游戏开发框架,广泛应用于iOS、Android、Windows等多个操作系统。本书以C++语言...
Cocos2d是一个开源的游戏开发框架,而Cocos2d-x是它的C++版本,主要应用于移动设备。本文将深入探讨Cocos2d-html5,它是一个基于HTML5的版本,允许开发者使用JavaScript进行游戏开发,非常适合那些希望从其他领域...
《Cocos2d-x实战C++卷》是关东升所著的一本深入探讨Cocos2d-x游戏引擎开发的专业书籍。Cocos2d-x是一个开源的、跨平台的2D游戏开发框架,广泛应用于iOS、Android、Windows等多个操作系统。本书以C++语言为主要编程...
Cocos2d-x是一个开源的游戏开发框架,广泛用于2D游戏、实时渲染应用程序和其他互动内容的制作。这个压缩包“cocos2d-x-3.1.zip”包含了Cocos2d-x框架的3.1版本,这是一个经典且相对旧的版本,可能对于那些寻找历史...
《Cocos2d-x实战 JS卷》是一本深入探讨Cocos2d-x游戏开发的专著,主要聚焦于使用JavaScript语言进行游戏编程。Cocos2d-x是一个开源的游戏开发框架,广泛应用于移动设备和桌面平台,支持iOS、Android、Windows等多...
《Cocos2d-x 3.x游戏开发实战》是一本深度探讨Cocos2d-x 3.x框架的游戏开发书籍,适合对游戏编程有兴趣的开发者学习。Cocos2d-x 是一个开源的、跨平台的2D游戏开发框架,广泛应用于iOS、Android、Windows等多平台的...
《Cocos2d-x 3.13.1与Spine 3.6集成详解》 Cocos2d-x是一个广泛使用的开源游戏开发框架,它基于C++,同时支持Lua和JavaScript等多种脚本语言,为开发者提供了高效、跨平台的游戏开发解决方案。在3.13.1版本中,...
标题中提到了"Cocos2d-x实战++JS卷++Cocos2d-JS开发+PDF电子书下载+带书签目录+完整",这里面包含了几个关键知识点: 1. Cocos2d-x:是一个开源的游戏开发框架,它主要用于开发跨平台的游戏和应用程序,支持iOS、...
Cocos2d-x是一款流行的开源游戏开发框架,它基于C++,并利用OpenGL进行图形渲染。在游戏开发中,特效的实现是至关重要的,能够极大地提升游戏的视觉体验和玩家的沉浸感。"Cocos2d-x 闪电特效"正是这样一个专题,它...