2015-01-12 2 views
0
var replacebg = SKAction.moveToY(bgTexture.size().height , duration: 0) 
    var replacebgForever = SKAction.repeatActionForever(replacebg) 

    bg.runAction(replacebgForever) 

화면을 터치 할 때마다 배경이 50 픽셀 아래로 이동합니다. 동일한 이미지를 사용하여 배경이 부족할 때 배경을 대체하고 싶습니다. 위의 코드를 시도했지만 작동하지 않고 모든 애니메이션을 중지합니다. 어떤 도움이 필요합니까? 고맙습니다.배경이 만기가되면 어떻게 대체합니까?

답변

0

update 방법이 SKScene 인 경우 화면 밖으로 나가면 background을 다시 설정할 수 있습니다.

랩 어라운드 효과를 만들려면 다음과 같은 두 가지 배경 스프라이트 노드를 만듭니다. 두 배경은 서로 위아래로 유지됩니다.

background1 = SKSpriteNode(texture: bgTexture) 
background1.position = CGPoint(x:CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame)) 
background1.size.height = self.frame.height 

background2 = SKSpriteNode(texture: bgTexture) 
background2.position = CGPoint(x:CGRectGetMidX(self.frame) , y: CGRectGetMidY(self.frame)+ self.frame.size.height) 
background2.size.height = self.frame.height 

self.addChild(background1) 
self.addChild(background2) 

이어서 touchesBegan 함수

if background1.position.y + background1.size.height/2 < 50 
{ 
    let diff = background1.position.y + background1.size.height/2 - 50 
    background1.position.y = self.frame.height + background1.size.height/2 + diff 
} 
else 
{ 
    background1.position.y -= 50 
} 
if background2.position.y + background2.size.height/2 < 50 
{ 
    let diff = background2.position.y + background2.size.height/2 - 50 
    background2.position.y = self.frame.height + background2.size.height/2 + diff 
} 
else 
{ 
    background2.position.y -= 50 
} 

위의 코드를 더 모듈화 할 수있다. 하지만 나는 너에게 맡긴다.

관련 문제