удаление спрайтов потерянной ссылки со страницы в кокосах 2d - PullRequest
1 голос
/ 30 марта 2012

Я снова и снова использую один спрайт (требование программы) для разных анимаций в разных местах прикосновения и сохраняю окончательное изображение после каждой анимации на экране [sprite spriteWithSpriteFrameName :@ "abc.png"].Теперь проблема в том, что после завершения всей анимации я хочу удалить окончательное изображение всей законченной анимации с экрана, но из-за повторного использования одного и того же спрайта спрайт имеет только ссылку на последнюю выполненную анимацию и использует [sprite removeFromParentAndCleanup: true] удалить только последнюю выполненную анимацию. Пожалуйста, помогите мне удалить всю выполненную анимацию spriteFrame.

вот пример кода

- (void) 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];

} - (void) draw2 {[[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];


}
...