Note that there are some explanatory texts on larger screens.

plurals
  1. POSprite frame animation
    primarykey
    data
    text
    <p>I am trying to make my sprite run a frame by frame animation, what i have so far is this.</p> <p>GameScreen.h</p> <pre><code>#import "cocos2d.h" #import &lt;UIKit/UIKit.h&gt; #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 </code></pre> <p>GameScreen.m</p> <pre><code>@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 &lt;= 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]; </code></pre> <p>}</p> <p>When i run the program, where the sprite should be is a black square and i get this following message in my debugger window</p> <p>2013-01-31 00:00:02.682 Dubstep Dash[428:907] cocos2d: CCTexture2D. Can't create Texture. cgImage is nil 2013-01-31 00:00:02.684 Dubstep Dash[428:907] cocos2d: Couldn't add image:Dubstep Dan_default.png in CCTextureCache</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload