首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CCSpriteBatchNode。改变纹理文件

CCSpriteBatchNode。改变纹理文件
EN

Stack Overflow用户
提问于 2012-02-16 03:51:27
回答 1查看 844关注 0票数 0

在我的应用程序中,我有大量的不同的动画我的雪碧,并将有更多的谭在以后的版本。这是相当困难使用纹理文件将数以百计的帧,所以我想做几个tham。所以,我写了这段代码:

代码语言:javascript
复制
    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时,我得到了以下错误:

*终止应用程序由于未指定的异常'NSInternalInconsistencyException',原因:'CCSprite:当setTexture使用CCSpriteBatchNode呈现时无法工作‘

如何切换纹理文件?或者还有另一种解决办法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-16 23:30:31

您不能更改CCSpriteBatchNode使用的纹理。

但是,您可以并且应该为将要使用的每个纹理创建一个。然后,无论何时设置显示框架,首先检查框架的纹理,并使用该纹理从当前sprite批处理节点中删除sprite,并将其添加到设置为使用与sprite框架相同的纹理的节点中。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9305286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档