저는 spriteKit에서 platformer 게임을 시작했으며 가로 모드에 약간의 문제가 있습니다. 난 내 영웅으로 점프를 할 때 , 나는landscape 모드가 spritekit 게임에서 제대로 작동하지 않습니다.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
와 영웅 동안 공중에 그리고 벽이나 물체와 충돌하고 그의 속도를 그리워하고 내가
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:positionInScene];
CGPoint posicionHero = [self.world childNodeWithName:@"hero"].position;
SKSpriteNode *touchHero = (SKSpriteNode *)[self nodeAtPoint:posicionhero];
//pragma mark -hero movement in the air
if ((touchedNode != touchHero)
&&
(positionInScene.x > [self.world childNodeWithName:@"hero"].position.x))
{
[[self.world childNodeWithName:@"hero"].physicsBody applyImpulse:CGVectorMake(5, 0)];
}
if ((touchedNode != touchHero)
&&
(positionInScene.x < [self.world childNodeWithName:@"hero"].position.x))
{
[[self.world childNodeWithName:@"hero"].physicsBody applyImpulse:CGVectorMake(-5, 0)];
}
}
를 사용하는 사용 그 속도를 유지하려면
. 세로 모드에서 테스트를 해봤지만 모든 것이 정상 이었지만 내 게임은 가로 모드 였으므로 마침내 가로 모드로 게임을 막았습니다. 이제 가로 모드로 테스트하고 문제가 있습니다. 점프에서 손가락을 앞으로 움직이면 아무 일도 일어나지 않기 때문입니다. 대신에 나는 그 움직임을 얻기 위해 손가락을 위쪽으로 움직여야합니다. 내 가로 모드에 대한 일부 기본 구성이 누락되었습니다. 어떤 도움도 감사 할 것입니다.
당신이 변화 시도해 봤어 X 좌표 :이 소스를 체크 아웃 자세한 내용은
예를 들어, 기본이와
viewDidLoad
을 SpriteKit 대체 할 수 있을까? 또한 locationInNode는 원점이 UIView와 같이 왼쪽 상단 구석이 아닌 왼쪽 하단 모서리에있는 좌표계를 사용합니다. – lucaslt89