cocos2d里面使用精灵表单(spritesheet)的好处

免责声明:本博客的所有原创文章,均有time_anime精心写作,供学习交流使用,切勿进行商业传播。同时,转载请不要移除本声明!


SpriteSheet精灵表单:每个游戏开发者都应该知道的基本概念。


看上图的游戏场景,它由不同的图形对象组成,有花、树、云朵和PixelGuy(就是那个小孩了)。所有这些可移动的游戏对象被称作精灵。


让我们看看一个特别的精灵,这个精灵是有着确定的像素宽度和高度的矩形图片。大小为140X140像素。

For eachpixel, some amount of memory is required to store its color. The exact amountdepends on the color depth - which is by default 32bit - and thus consumes 4bytes. So the complete memory usage of PixelGuy is 140x140x4 which is 76kb.


Dependingon your graphics hardware you might only be able to use particular sizes foryour sprites - e.g. a power of 2 or even worse - squared sprites.


For this asprite must be padded with additional unused pixels to match the hardware‘sconstraints. To meet this requirement PixelGuy‘s sprite must be extended to256x256 pixels. This increases the memory usage - now consuming 256kb - whichis more than three times the size of the original sprite.


Not muchfor a single sprite I must admit - but imagine creating a game with manyobjects, characters and animation phases. You might easily end up with hundredsof sprites - each of them wasting precious resources.


But what if youcould use the wasted memory after all? Imagine packing another sprite into thatspace!

The result is calleda sprite sheet!

Now only thecomplete sheet has to meet the hardware constraints. As you see the memoryusage is now much lower than it would be using individual sprites.


Butthere's still more we can do! Let‘s squeeze out the transparent parts of thesprites, packing them even tighter. In our example we have now reduced thememory by another 50%!


But wait!There's even more we can do - if memory is scarce. In a standard 32bit colorformat each color channel and the transparency is represented by 8 bits -totaling 4 bytes for each pixel. We can reduce the color depth to 16bit bysqueezing out some colors. The quality of the reduction can be improved byapplying dithering. The result reduces memory usage by 50%!


In thefirst part, you saw how sprite sheets can help you reduce memory usage for yourgame. In the second part, you are going to learn how the performance of yourgame can be increased with sprite sheets.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值