나는 무작위적인 장애물이 화면의 상단에서 떨어지면서 플레이어가 그것을 피할 수있는 게임을 만들고 있습니다. 화면 아래에있는 노드 (장애물)를 삭제하는 방법을 구현하는 데 문제가 있습니다. 장애물을 산란하는 방식이 단순 해 보일 수도 있지만 혼란 스럽습니다.스프라이트 키트의 화면 아래에있는 노드를 삭제하는 방법은 무엇입니까?
- (void)spawnNewObstacles
{
//spawn obstacles
SKSpriteNode *obstacle = [SKSpriteNode spriteNodeWithImageNamed:@"black.png"];
int position = arc4random() % 320 + 1;
obstacle.position = CGPointMake(position, 800);
obstacle.size = CGSizeMake(200, 20);
obstacle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:obstacle.frame.size];
obstacle.physicsBody.dynamic = YES;
[self addChild:obstacle];
[obstacles addObject:obstacle]; //obstacles is an NSMutableArray
[obstacle.physicsBody applyImpulse:CGVectorMake(0, -80.0f)];
[self performSelector:@selector(spawnNewObstacles) withObject:nil afterDelay:0.25];
}
그리고 여기가 화면 아래로 떨어지는 것과 삭제하는 (그러나 실패)하고있어 방법은 다음과 같습니다 :
-(void)update:(CFTimeInterval)currentTime
{
for(int i=0;i<obstacles.count;i++)
{
NSLog(@"Removed an Obstacle"); //this log isn't showing so i concluded that it wasn't working
SKSpriteNode *obstacle = [obstacles objectAtIndex:i];
if(obstacle.position.y<0)
{
[obstacle removeFromParent];
}
}
}
방법 U 사람이 난을 제안 여기에 내가 장애를 생성하는 방법이다 이 작업을 수행?
p.s. 중단 점을 설정
obstacles = [NSMutableArray array];
과 obstacles
있는지 확인 : PLZ ... 코드로의 소리에서
이 충분하다 또는 메모리를 절약하는 더 좋은 방법 – vink007
그만이면 충분합니다. – LearnCocos2D