我有一个问题,从数组中删除项目..
首先:我有一个 int 类型的变量,叫做 zan。在我的 HelloWordScene.h
int zan;
NSMutableArray * targets;
NSMutableArray *projectiles;
在我的 HelloWordScene.m 中。我有一个对象,动画:
-(id) init {
if((self = [super init])) {
[self schedule:@selector(update:)];
_targets = [[NSMutableArray alloc] init];
_projectiles = [[NSMutableArray alloc] init];
}
[self schedule:@selector(gameLogic:) interval:3];
return self;
}
在我的选择器中,我增加了 var:
-(void)gameLogic:(ccTime)dt {
[self addTarget];
zan ++;
}
后来我有一个动画,我有一个 addTarget:
// This loads an image of the same name (but ending in png), and goes through the
// plist to add definitions of each frame to the cache.
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"zancudo.plist"];
// Create a sprite sheet with the images
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"zancudo.png"];
[self addChild:spriteSheet];
// Load up the frames of our animation
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 4; ++i) {
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"zancu000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
// Create a sprite for our bear
CGSize winSize = [CCDirector sharedDirector].winSize;
self.bear = [CCSprite spriteWithSpriteFrameName:@"zancu0001.png"];
//random position
int minY = _bear.contentSize.width/2;
int maxY = winSize.width - _bear.contentSize.width/2;
int rangeY = maxY - minY;
int actualX = (arc4random() % rangeY) + minY;
// Create the target slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
_bear.position = ccp(actualX,winSize.height + (_bear.contentSize.height/2));
self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
//animation
[spriteSheet addChild:_bear];
//∫aqui pasar un for para poder saber que position es
CCLOG(@"cantidad de zancudos%d",zan);
[_targets insertObject:_bear atIndex:zan];
我已经为索引删除了一个可变的 _target - 我有一个选择器更新。尝试删除一个可变数组。
for (CCSprite *target in targetsToDelete) {
if (_targets.count!=0) {
for (int j=1; j==_targets.count; j++) {
[_targets removeObjectAtIndex:j];
}
}
我需要帮助