0
我創建了一個名爲Player類......在init方法我想用一個CCSpriteBatchNode:CCSpriteBatchNode
@interface Player : CCNode {
CCSprite *player;
CCSpriteBatchNode *spriteSheet;
CCAction *walkAction;
int playerSpeed;
int xPos;
int yPos;
}
@property (nonatomic, retain) CCSprite *player;
@property (nonatomic, retain) CCSpriteBatchNode *spriteSheet;
@property (nonatomic, retain) CCAction *walkAction;
@property int playerSpeed;
@property int xPos;
@property int yPos;
-(id)init {
if((self=[super init])) {
playerSpeed = 70;
xPos = 160;
yPos = 10;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"bugA.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"bugA.png"];
[player useBatchNode:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for (int i = 1; i <= 8 ; ++i) {
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bug%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
player = [CCSprite spriteWithSpriteFrameName:@"bug1.png"];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[player runAction:walkAction];
[spriteSheet addChild:player];
}
return self;
}
然後在HelloWorldScene我想使用這個類動畫
Player *pl = [Player node];
[self addChild:pl.player];
但沒有任何工作。我究竟做錯了什麼? 謝謝。