【问题标题】:Sprite frame animation精灵帧动画
【发布时间】:2014-01-08 04:17:53
【问题描述】:

我正在尝试让我的精灵逐帧运行动画,到目前为止我所拥有的就是这个。

GameScreen.h

#import "cocos2d.h"
#import <UIKit/UIKit.h> 
#import "GamePad.h"


@interface GameScreen : CCLayer
{
    CCSprite *_character;
    CCAction *_walkAction;
    CCAction *_moveAction;
    BOOL _moving;
}

@property (nonatomic, retain) CCSprite *character;
@property (nonatomic, retain) CCAction *walkAction;
@property (nonatomic, retain) CCAction *moveAction;

+(CCScene *) scene;


@end

GameScreen.m

@implementation GameScreen

@synthesize character = _character;
@synthesize moveAction = _moveAction;
@synthesize walkAction = _walkAction;



+(id) scene
{
    CCScene *scene = [CCScene node];

    GameScreen *layer = [GameScreen node];

    [scene addChild: layer];

    return scene;
}

-(id) init
{

    if( (self=[super init] )) {



        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
         @"Dubstep Dan_default.plist"];
        CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
                                          batchNodeWithFile:@"Dubstep Dan_default.png"];
        [self addChild:spriteSheet];

        NSMutableArray *walkAnimFrames = [NSMutableArray array];
        for(int i = 1; i <= 8; ++i) {
            [walkAnimFrames addObject:
             [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
              [NSString stringWithFormat:@"1-%d.png", i]]];
        }



        CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];



        CGSize winSize = [CCDirector sharedDirector].winSize;
        self.character = [CCSprite spriteWithSpriteFrameName:@"1-1.png"];
        _character.position = ccp(winSize.width/2, winSize.height/2);
        self.walkAction = [CCRepeatForever actionWithAction:
                           [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
        [_character runAction:_walkAction];
        [spriteSheet addChild:_character];

}

当我运行程序时,精灵应该是一个黑色方块,我在调试器窗口中收到以下消息

2013-01-31 00:00:02.682 Dubstep Dash[428:907] cocos2d: CCTexture2D。无法创建纹理。 cgImage 为零 2013-01-31 00:00:02.684 Dubstep Dash[428:907] cocos2d:无法在 CCTextureCache 中添加图像:Dubstep Dan_default.png

【问题讨论】:

  • 检查该文件是否存在于您的项目中,并且具有相同的名称,包括大写/小写
  • 所有文件都在 plist 中,名称正确

标签: xcode cocos2d-iphone


【解决方案1】:

更正您的文件名,如Dubstep_Dan_default.plist

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-01
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多