在cocos 2d中从页面中删除丢失的引用精灵

时间:2012-03-30 07:34:51

标签: sprite

我一次又一次地使用单个精灵(程序要求)在不同的触摸位置上使用不同的动画,并在屏幕上的每个动画后保留最终图像 [sprite spriteWithSpriteFrameName :@" abc.png"]。 现在的问题是,在完成所有动画后,我想从屏幕中删除所有已完成的动画的最终图像,但由于一次又一次使用相同的精灵,精灵只有最后完成动画的参考并使用 [ sprite removeFromParentAndCleanup:true] 只删除上次完成的动画。请帮我删除所有已完成的动画spriteFrame。

这是示例代码

- (无效)DRAW1 {     [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@" a.plist"];

// Create a sprite sheet with the  images
spritebatch= [CCSpriteBatchNode batchNodeWithFile:@"a.png"];
[self addChild:sprite z:12];
// Load up the frames of our animation

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

}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:animFrames delay:.1f];

sprite=[CCSprite spriteWithSpriteFrameName:@"crta13.png"];

[self addChild:sprite z:20];
drawaction = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:walkAnim] times:1];
 //[CCRepeat actionWithAction: [CCAnimate actionWithAnimation:animation] times:1];
[sprite runAction:drawaction];

} - (无效)DRAW2 {   [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@&#34; a.plist&#34;];

// Create a sprite sheet with the  images
spritebatch= [CCSpriteBatchNode batchNodeWithFile:@"a.png"];
[self addChild:sprite z:12];
// Load up the frames of our animation

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

}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:animFrames delay:.1f];

sprite=[CCSprite spriteWithSpriteFrameName:@"crta13.png"];

[self addChild:sprite z:20];
drawaction = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:walkAnim] times:1];
 //[CCRepeat actionWithAction: [CCAnimate actionWithAnimation:animation] times:1];
[sprite runAction:drawaction];


}

0 个答案:

没有答案
相关问题