我正在做一個小遊戲,這裏是怎麼回事一些示例代碼:的NSMutableArray和batchNode問題
-(id) init
{
self.arrowProjectileArray = [[[NSMutableArray alloc] init] autorelease];
self.batchNode = [CCSpriteBatchNode batchNodeWithTexture:[[CCTextureCache sharedTextureCache] addImage:@"arrow.png"]];
[self addChild:_batchNode z:2];
for (CCSprite *projectile in _arrowProjectileArray) {
[_batchNode removeChild:projectile cleanup:YES];
}
[_arrowProjectileArray removeAllObjects];
self.nextProjectile = nil;
}
}
-(void) callEveryFrame:(ccTime)dt{
for (int i = 0; i < [_arrowProjectileArray count];i++) {
CCSprite *cursprite = [_arrowProjectileArray objectAtIndex:i];
if (cursprite.tag == 1) {
float x = theSpot.x+10;
float y = theSpot.y+10;
cursprite.position = ccp(x, y);
}
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[_batchNode addChild:_nextProjectile z:1 tag:1];
[_arrowProjectileArray addObject: _nextProjectile];
[self spriteMoveFinished];
}
-(void) dealloc
{
self.arrowProjectileArray = nil;
self.nextProjectile = nil;
[super dealloc];
}
,我是包含的代碼,是有關箭頭的投影的唯一代碼。 箭頭射得很好,問題在於我每次拍攝這個愚蠢的東西時,我認爲它會拍攝一個新的箭頭,但是會在該箭頭上放置多個箭頭,並使其看起來像一個肥胖的箭頭像素。我究竟做錯了什麼?我不太熟悉NSMutableArray,但我目前被卡住了。
我不認爲你閱讀所有的代碼...箭頭被添加到陣列中,他們拍出來的。這只是它重複使用相同的箭頭和做一些奇怪的事情。看看touchesBegan – Gabe