2014-04-23 6 views
0

테스트 목적으로 SpriteKit으로 공간 사수를 개발 중입니다. 게임 필드는 700 x 700 픽셀/포인트입니다. 분명히 아이폰 화면에 맞지 않습니다. 그것은 플레이어 + 적 + 총알 + 소행성에 영향을 미치는 일종의 스크롤링이 필요하다는 것을 의미합니다. 나는 Google을 검색했지만 스크롤에 관한 대부분의 주제는 Cocos2D를 참조하고 거의 항상 Cocos2D 특정 기능을 나타내며 스프라이트 키트는 제공하지 않습니다. 그래서 이것은 첫 번째 게임이므로 다 방향 스크롤을 구현하는 것이 올바른지 잘 모르겠습니다. 여러분이 저에게 도움이되는 해결책이나 힌트/튜토리얼 또는 기타 도움을 주실 수 있기를 바랍니다. DSpriteKit 다 방향 스크롤

+0

덕분에 그것을 해결? 사람들은 당신을 위해 당신의 게임을 프로그램하고 싶지 않습니다. 힌트 나 트윗을 원하지만 약간의 노력을 보여 주길 바랍니다. –

답변

2

"우주선"을 만들고 카메라 노드를 만들고 업데이트 방법으로 카메라를 항상 우주선의 중심에 두십시오. . How to make camera follow SKNode in Sprite Kit?

-(void)centerOnNode:(SKNode*)node { 
    CGPoint cameraPositionInScene = [node.scene convertPoint:node.position fromNode:node.parent]; 
    cameraPositionInScene.x = 0; 
    node.parent.position = CGPointMake(node.parent.position.x - cameraPositionInScene.x, node.parent.position.y - cameraPositionInScene.y); 
} 

그럼 어떻게 배의 움직임을 자신 만의 게임 메커니즘을 파악해야하지만 단순히 의미하는 경우 선박이 당신이 SKActions을 사용할 수 있습니다 손가락을 다음과 :이 질문에 대한 유사한

뭔가 손가락 위치에 애니메이션을 적용 할 수 있습니다. 예 : https://stackoverflow.com/a/19172574/525576

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    for (UITouch *touch in touches) { 

     for (UITouch *touch in touches) { 

      CGPoint location = [touch locationInNode:self]; 

      CGPoint diff = CGPointMake(location.x - _myPlayer.position.x, location.y - _myPlayer.position.y); 

      CGFloat angleRadians = atan2f(diff.y, diff.x); 

      [_myPlayer runAction:[SKAction sequence:@[ 
           [SKAction rotateToAngle:angleRadians duration:1.0], 
           [SKAction moveByX:diff.x y:diff.y duration:3.0] 
           ]]]; 
     } 
    } 
} 
+0

안녕하세요,이 게시물은 많은 도움이되었습니다. 나는 내 자신의 "카메라"기능을 다음과 같이 구현하려고 시도했다 : 'float xDisFromCenter = 0.f; float yDisFromCenter = 0.f; yDisFromCenter = (world.position.y + player.position.y) - (self.size.height/2); xDisFromCenter = (world.position.x + player.position.x) - (self.size.width/2); world.position = CGPointMake (world.position.x-xDisFromCenter, world.position.y-yDisFromCenter); ' 나는 세상을 움직이고있다. if (newPos.x> 0) xDisFromCenter = 0.f; if (newPos.x <-20) xDisFromCenter = 0.f;'그러나 매번 작동하지 않습니다. / – user1990524

0

당신이 시도 무엇, 레이 wenderlich

CGSize winSize = self.size; 

int x = MAX(player.position.x, winSize.width/2); 
int y = MAX(player.position.y, winSize.height/2); 
x = MIN(x, worldSize.width - winSize.width/2); 
y = MIN(y, worldSize.height - winSize.height/ 2); 
CGPoint actualPosition = CGPointMake(x, y); 

CGPoint centerOfView = CGPointMake(winSize.width/2, winSize.height/2); 
CGPoint viewPoint = ccpSub(centerOfView, actualPosition); 

world.position = viewPoint;