• <legend id='h3vof'><style id='h3vof'><dir id='h3vof'><q id='h3vof'></q></dir></style></legend>

    1. <tfoot id='h3vof'></tfoot>

      <i id='h3vof'><tr id='h3vof'><dt id='h3vof'><q id='h3vof'><span id='h3vof'><b id='h3vof'><form id='h3vof'><ins id='h3vof'></ins><ul id='h3vof'></ul><sub id='h3vof'></sub></form><legend id='h3vof'></legend><bdo id='h3vof'><pre id='h3vof'><center id='h3vof'></center></pre></bdo></b><th id='h3vof'></th></span></q></dt></tr></i><div id='h3vof'><tfoot id='h3vof'></tfoot><dl id='h3vof'><fieldset id='h3vof'></fieldset></dl></div>

        <small id='h3vof'></small><noframes id='h3vof'>

          <bdo id='h3vof'></bdo><ul id='h3vof'></ul>

      1. cocos2d如何快速绘制背景?

        时间:2024-08-12

      2. <tfoot id='imVn0'></tfoot>
      3. <small id='imVn0'></small><noframes id='imVn0'>

            <bdo id='imVn0'></bdo><ul id='imVn0'></ul>

            1. <i id='imVn0'><tr id='imVn0'><dt id='imVn0'><q id='imVn0'><span id='imVn0'><b id='imVn0'><form id='imVn0'><ins id='imVn0'></ins><ul id='imVn0'></ul><sub id='imVn0'></sub></form><legend id='imVn0'></legend><bdo id='imVn0'><pre id='imVn0'><center id='imVn0'></center></pre></bdo></b><th id='imVn0'></th></span></q></dt></tr></i><div id='imVn0'><tfoot id='imVn0'></tfoot><dl id='imVn0'><fieldset id='imVn0'></fieldset></dl></div>
                  <legend id='imVn0'><style id='imVn0'><dir id='imVn0'><q id='imVn0'></q></dir></style></legend>
                    <tbody id='imVn0'></tbody>
                  本文介绍了cocos2d如何快速绘制背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 cocos2d 在我的 iPad 上玩一个小游戏,我遇到了一些性能问题.我有一个 512x512 的图像平铺作为我的背景.这给了我大约 40fps 和 20 个精灵(在 CCSpriteBatchNode 中),背景代码是这样的:

                  I'm toying with a small game on my iPad using cocos2d and I've run into some performance worries. I have a 512x512 image tiled as my background. That gives me around 40fps with 20 sprites (in a CCSpriteBatchNode), the code for the background is this:

                  CCSprite *background;
                  background = [CCSprite spriteWithFile:@"oak.png" rect : CGRectMake(0,
                                                                                     0,
                                                                                     size.width,
                                                                                     size.height)];
                  background.position =  ccp( size.width /2 , size.height/2 );
                          
                  ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
                  [background.texture setTexParameters: &params];
                  

                  如果我移除背景,我会得到稳定的 60fps.

                  If I remove the background I get a solid 60fps.

                  我已尝试将图像转换为 PVRTC,但确实提供了额外的一两帧.我使用 1024x768 图像而不是平铺版本获得相同的帧速率.

                  I've tried converting the image to PVRTC and that did give an extra fps or two. I get identical framerates using a 1024x768 image instead of the tiled version.

                  因为我的背景将保持轴对齐、未缩放且通常是静态的.我认为应该有比将它作为常规 CCSprite 更快的方法来绘制它?

                  Since my background will remain axis aligned, unscaled and generally static. I figure there should be a faster way to draw it than having it as a regular CCSprite?

                  推荐答案

                  原来 cocos2d 以神秘的方式移动.将背景添加到否则为空的包装 CCSprite 可使帧率恢复到 60:

                  Turns out cocos2d moves in mysterious ways. Adding the background to an otherwise empty wrapping CCSprite gets the framerate back up to 60:

                  CCSprite *spback = [(CCSprite*)[CCSprite alloc] init];
                  [self addChild:spback];
                  
                  CCSprite *sp = [CCSprite spriteWithFile:@"Background.png"];
                  sp.position = ccp(1024/2, 768/2);
                  [spback addChild:sp];
                  

                  这要归功于 cocos2d 论坛上的 yaoligang.

                  Credits for this goes to yaoligang on the cocos2d forums.

                  这篇关于cocos2d如何快速绘制背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 cocos2d 处理对 CCSprite 的触摸的最佳实践 下一篇:cocos2d中的水效果

                  相关文章

                  <legend id='xuyaP'><style id='xuyaP'><dir id='xuyaP'><q id='xuyaP'></q></dir></style></legend>
                  <i id='xuyaP'><tr id='xuyaP'><dt id='xuyaP'><q id='xuyaP'><span id='xuyaP'><b id='xuyaP'><form id='xuyaP'><ins id='xuyaP'></ins><ul id='xuyaP'></ul><sub id='xuyaP'></sub></form><legend id='xuyaP'></legend><bdo id='xuyaP'><pre id='xuyaP'><center id='xuyaP'></center></pre></bdo></b><th id='xuyaP'></th></span></q></dt></tr></i><div id='xuyaP'><tfoot id='xuyaP'></tfoot><dl id='xuyaP'><fieldset id='xuyaP'></fieldset></dl></div>

                  <tfoot id='xuyaP'></tfoot>
                  • <bdo id='xuyaP'></bdo><ul id='xuyaP'></ul>

                    1. <small id='xuyaP'></small><noframes id='xuyaP'>