1
-(void) update:(ccTime *)dt{
for(int i=0; i < [objects count]; i++){
CCSprite *obj = (CCSprite *) [objects objectAtIndex:i];
if(obj.position.y <= 40){
[obj stopAllActions];
[self removeChild:obj cleanup:YES]; /* ?? */
[objects removeObjectAtIndex:i];
}
}
卸下精靈我期待這個代碼刪除精靈,但它不工作。精靈仍然在屏幕上。我在這裏做錯了,請幫忙。謝謝。
編輯:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"vase.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"vase.png"];
[self addChild:spriteSheet z:1 tag:1];
//CCSpriteFrame must be created for each animation frame.
NSMutableArray *animFrames = [NSMutableArray array];
for (int i = 1; i <= 3; i++) {
NSString *file = [NSString stringWithFormat:@"frame %d.png", i];
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:file];
[animFrames addObject:frame];
}
//Sprite is positioned and then animated.
CCSprite *player = [CCSprite spriteWithSpriteFrameName:@"frame 1.png"];
CCAnimation *anim = [CCAnimation animationWithFrames:animFrames delay:0.20f];
CCRepeat *repeat = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:anim restoreOriginalFrame:YES] times:3];
[player runAction:repeat];
player.position = startPostion;
[spriteSheet addChild:player];
作爲Sprite「obj」是動畫精靈。我正在使用spritesheet,可能是這裏的問題嗎? – xibic
請顯示代碼如何創建精靈 – Andrew
那裏我正在創建精靈。 – xibic