• <small id='qDdhR'></small><noframes id='qDdhR'>

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

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

      2. CCSpriteBatchNode.更改纹理文件

        CCSpriteBatchNode. change texture file(CCSpriteBatchNode.更改纹理文件)

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

          <tfoot id='ywyCz'></tfoot>

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

              <tbody id='ywyCz'></tbody>
                • <bdo id='ywyCz'></bdo><ul id='ywyCz'></ul>
                  <legend id='ywyCz'><style id='ywyCz'><dir id='ywyCz'><q id='ywyCz'></q></dir></style></legend>
                  本文介绍了CCSpriteBatchNode.更改纹理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我的精灵有大量不同的动画,在以后的版本中还会有更多.使用纹理文件将数百帧是相当困难的,所以我想制作几个.所以,我写了这段代码:

                  In my app I have a great number of different animations of my sprite, and there will be more of tham in later versions. It is quite difficult to use texture file will hundreds of frames, so I whould like to make several of tham. So, I wrote this code:

                      if (running)
                      {
                          NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_RUN];
                          if (!inAir)
                          {
                              currentFrame++;
                              if (currentFrame>=[animations count]*ANIMATION_ITERATION) 
                                  currentFrame = 0;
                          }
                          else
                          {
                              currentFrame = 2;
                          }
                          PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
                          [sprite setFlipX:(moveingDirection)];
                          [sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]];
                      }
                      else
                      {
                          NSArray * animations = [[physicalBody getAnimationList] objectForKey:ANIMATION_STAND];
                          currentFrame++;
                          if (currentFrame>=[animations count]*ANIMATION_ITERATION) 
                              currentFrame = 0;
                          PhysicsSprite *sprite = (PhysicsSprite*)[physicalBody getSprite];
                          [sprite setFlipX:(moveingDirection)];
                          [sprite setDisplayFrame:[animations objectAtIndex:currentFrame/ANIMATION_ITERATION]];   //error here
                      }
                  

                  动画数组是从不同的 *.png 创建的,当它尝试切换 tham 时,我收到了这个错误:

                  Array of animations was created from different *.png, and when it tries to switch tham, i got this error:

                  * 由于未捕获的异常NSInternalInconsistencyException"而终止应用程序,原因:CCSprite: setTexture"使用 CCSpriteBatchNode 渲染精灵时不起作用

                  * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: setTexture doesn't work when the sprite is rendered using a CCSpriteBatchNode'

                  如何切换纹理文件?或者可能有其他解决方案?

                  How can I switch texture files? Or may be there is another solution?

                  推荐答案

                  您无法更改 CCSpriteBatchNode 使用的纹理.

                  You can't change the texture a CCSpriteBatchNode uses.

                  但是,您可以并且应该为您使用的每个纹理创建一个 CCSpriteBatchNode.然后,每当您设置显示帧时,首先检查帧的纹理并使用它从当前精灵批处理节点中删除精灵,并将其添加到设置为使用与精灵帧相同的纹理的节点.

                  However you can and should create a CCSpriteBatchNode for each texture that you are going to use. Then, whenever you set a display frame first check the frame's texture and use that to remove the sprite from the current sprite batch node and add it to the one that is setup to use the same texture as the sprite frame.

                  但是,这可能会导致 z 排序问题.在最坏的情况下,您只需重新设计动画或不使用精灵批处理节点.

                  However this can lead to z ordering issues. In the worst case you'll simply have to either redesign your animations or don't use sprite batch nodes.

                  这篇关于CCSpriteBatchNode.更改纹理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                    <tbody id='Fv53D'></tbody>
                  • <small id='Fv53D'></small><noframes id='Fv53D'>

                    <tfoot id='Fv53D'></tfoot><legend id='Fv53D'><style id='Fv53D'><dir id='Fv53D'><q id='Fv53D'></q></dir></style></legend>

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

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