캐릭터가 영원히 오른쪽으로 실행되는 게임을 만들려고합니다 (게임은 가로 방향입니다). 지상에는 캐릭터가 뛰어 넘을 수있는 스파이크가 있습니다. 현재는 캐릭터가 특정 거리에 도달하면 무작위로 구성된 스파이크가 만들어지고 체크 포인트 거리가 뒤로 밀리는 등 거의 체크 포인트와 같은 스타일로 스파이크가 새로 생성됩니다 (다소 임의적입니다). . 스파이크와 함께, 나는 땅을 이루는 타일을 만드는 데 사용되는 별개이지만 매우 유사한 체크 포인트와 같은 시스템을 가지고 있습니다.특정 노드를 제거하는 스프라이트 키트
- (void) didSimulatePhysics {
if (player.position.x > endlessX) {
int random = player.position.x + self.frame.size.width;
[self createSpike:random];
endlessX += self.frame.size.width/2.2 + arc4random_uniform(30);
}
if (player.position.x + self.frame.size.width > endlessGroundX) {
[self createGround:endlessGroundX];
endlessGroundX += tile1.frame.size.width;
}
[self centerOnNode: player];
}
createSpike 및 createGround 방법의 파라미터는 SKSpriteNodes위한 단지 'X'의 값이다 이 부분 내 코드는 'endlessX'및 'endlessGroundX'는 검사 값이다. 캐릭터 자체가 움직이며 스파이크와 타일이 고정되어 있으므로 현재이 기능을 사용하고 있습니다. 즉, 캐릭터가 마찰 또는 같은 다른 힘의 운동 에너지 중 하나를 잃지 않을 것으로
-(void) createPlayer {
player = [SKSpriteNode spriteNodeWithImageNamed:@"base"];
player.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
player.name = @"player";
player.zPosition = 60;
player.xScale = 0.8;
player.yScale = 0.8;
player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:player.frame.size.height/2];
player.physicsBody.mass = 1;
player.physicsBody.linearDamping = 0.0;
player.physicsBody.angularDamping = 0.0;
player.physicsBody.friction = 0.0;
player.physicsBody.restitution = 0.0;
player.physicsBody.allowsRotation = NO;
player.physicsBody.dynamic = YES;
player.physicsBody.velocity = CGVectorMake(400, 0);
player.physicsBody.categoryBitMask = playerCategory;
player.physicsBody.collisionBitMask = wallCategory;
player.physicsBody.contactTestBitMask = wallCategory | spikeCategory;
[myWorld addChild:player];
}
: 이것은 내가 캐릭터를 만드는 오전 방법이다.
- (void) centerOnNode: (SKSpriteNode *) node {
CGPoint cameraPositionInScene = [node.scene convertPoint:node.position fromNode:node.parent];
node.parent.position = CGPointMake(self.frame.size.width/5 + node.parent.position.x - cameraPositionInScene.x, node.parent.position.y);
}
내가 '에서이 메서드를 호출 오전 : 그럼, 캐릭터가 항상 화면에 같은 x 방향의 위치에 남아 있도록 사과 자신의 모험 게임에서 사용되는 방법'노드 센터 '를 사용하고 있습니다 didSimulatePhysics. '
When I run this for some time, the programs gets slower and slower. I am guessing that that is due to the fact that I am never removing these nodes and they are always being added. However, to fix this problem, I tried doing something like this:
-(void)update:(CFTimeInterval)currentTime {
[self enumerateChildNodesWithName:@"*" usingBlock:^(SKNode *node, BOOL *stop) {
if (node.position.x + 50 < player.position.x) {
[node removeFromParent];
}
}];
}
합니다 (+50 단지 노드를 제거하기 전에 화면 밖으로 있는지 확인하는 것) 그러나, 나는이 대신 '경우'문을 만족하는 특정 노드를 제거했을 때, 프로그램은 모든 스프라이트 노드를 제거합니다. 이 문제를 해결하기 위해 누락 된 다른 방법이나 무언가가 있습니까? 아니면 특정 노드를 제거하는 다른 간단한 방법이 있습니까?
디버거 사용 방법을 알고 있습니까? if 문 블록 내에서 중단 점을 설정하고 값이 예상 한 값인지 확인하는 것은 어떻습니까? – prototypical