2017-01-23 19 views
1

Before "Buy Ship" is pressed 그래서 나는 선수들이 새로운 선박을 살 수있는 가게를 만들려고 노력하고 있습니다. 플레이어가 "버튼 구입"이미지를 클릭하면 이미지와 텍스트의 조합을 볼 수있게하여 일종의 고화질 화면으로 사용하기를 원합니다. 다행스럽게도 여기서 내가 무엇을 의미하는지 볼 수 있습니다. 나는 또한 당신이 저에게 구조 상자 외 모든 것을 어둡게하는 방법을 말할 수 있다면 크게 감사 할 것입니다. After "Buy Ship" is pressed. 모든 물건을 준비하고 숨길SKScene에서 하위 뷰를 만드는 방법은 무엇입니까?

import Foundation 
import SpriteKit 

class ShopPage1: SKScene{ 


override func didMove(to view: SKView) { 

    let background = SKSpriteNode(imageNamed: "background") 
    background.position = CGPoint(x: self.size.width/2, y: self.size.height/2) 
    background.zPosition = 0 
    self.addChild(background) 

    let balance = SKLabelNode(fontNamed: "The Bold Font") 
    balance.text = "$\(balanceAmount)" 
    balance.fontSize = 100 
    balance.fontColor = SKColor.green 
    balance.position = CGPoint(x: self.size.width/2, y: self.size.height*0.87) 
    balance.zPosition = 1 
    self.addChild(balance) 

    let backToMainMenuButton = SKSpriteNode(imageNamed: "backButton2") 
    backToMainMenuButton.position = CGPoint(x: self.size.width*0.25, y: self.size.height*0.89) 
    backToMainMenuButton.zPosition = 1 
    backToMainMenuButton.size = CGSize(width: 200, height: 200) 
    backToMainMenuButton.name = "backToMainMenuButton" 
    self.addChild(backToMainMenuButton) 

    let shipNameLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipNameLabel.text = "Stealth" 
    shipNameLabel.fontSize = 200 
    shipNameLabel.fontColor = SKColor.white 
    shipNameLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.60) 
    shipNameLabel.zPosition = 1 
    shipNameLabel.name = "shipNameLabel" 
    self.addChild(shipNameLabel) 

    let nextShipButton = SKSpriteNode(imageNamed: "nextShipButton1") 
    nextShipButton.position = CGPoint(x: self.size.width*0.75, y: self.size.height*0.40) 
    nextShipButton.zPosition = 1 
    nextShipButton.size = CGSize(width: 300, height: 300) 
    nextShipButton.name = "nextShipButton" 
    self.addChild(nextShipButton) 


    let nextShipClick = SKLabelNode(fontNamed: "The Bold Font") 
    nextShipClick.text = "▲" 
    nextShipClick.fontSize = 300 
    nextShipClick.fontColor = UIColor.clear 
    nextShipClick.position = CGPoint(x: self.size.width*0.753, y: self.size.height*0.36) 
    nextShipClick.zPosition = 2 
    nextShipClick.name = "nextShipClick" 
    self.addChild(nextShipClick) 


    let shipForSale = SKSpriteNode(imageNamed: "playerShip4") 
    shipForSale.position = CGPoint(x: self.size.width/2, y: self.size.height*0.40) 
    shipForSale.zPosition = 1 
    shipForSale.size = CGSize(width: 150, height: 300) 
    self.addChild(shipForSale) 

    let shipPodium = SKSpriteNode(imageNamed: "shipPodium") 
    shipPodium.position = CGPoint(x: self.size.width*0.527, y: self.size.height*0.31) 
    shipPodium.zPosition = 1 
    shipPodium.size = CGSize(width: 1200, height: 70) 
    self.addChild(shipPodium) 

    let shipsCostLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipsCostLabel.text = "$500" 
    shipsCostLabel.fontSize = 200 
    shipsCostLabel.fontColor = SKColor.white 
    shipsCostLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.20) 
    shipsCostLabel.zPosition = 1 
    self.addChild(shipsCostLabel) 

    let shipBuyButton = SKSpriteNode(imageNamed: "shipBuyButton") 
    shipBuyButton.position = CGPoint(x: self.size.width*0.54, y: self.size.height*0.15) 
    shipBuyButton.zPosition = 1 
    shipBuyButton.size = CGSize(width: 1500, height: 900) 
    shipBuyButton.name = "shipBuyButton" 
    self.addChild(shipBuyButton) 

    let conformationBackground = SKSpriteNode(imageNamed: "conformationBackground") 
    conformationBackground.position = CGPoint(x: self.size.width*0.51, y: self.size.height*0.40) 
    conformationBackground.zPosition = 2 
    conformationBackground.size = CGSize(width: 1300, height: 1400) 
    conformationBackground.name = "conformationBackground" 
    self.addChild(conformationBackground) 

    let conformationScreenTextTop = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextTop.text = "Are you sure you wish to" 
    conformationScreenTextTop.fontSize = 80 
    conformationScreenTextTop.fontColor = SKColor.white 
    conformationScreenTextTop.position = CGPoint(x: self.size.width/2, y: self.size.height*0.46) 
    conformationScreenTextTop.zPosition = 3 
    self.addChild(conformationScreenTextTop) 

    let conformationScreenTextBottom = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextBottom.text = "pruchase this ship?" 
    conformationScreenTextBottom.fontSize = 80 
    conformationScreenTextBottom.fontColor = SKColor.white 
    conformationScreenTextBottom.position = CGPoint(x: self.size.width/2, y: self.size.height*0.41) 
    conformationScreenTextBottom.zPosition = 3 
    self.addChild(conformationScreenTextBottom) 

    let conformationScreenTextYes = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextYes.text = "Yes" 
    conformationScreenTextYes.fontSize = 150 
    conformationScreenTextYes.fontColor = SKColor.green 
    conformationScreenTextYes.position = CGPoint(x: self.size.width*0.30, y: self.size.height*0.30) 
    conformationScreenTextYes.zPosition = 3 
    self.addChild(conformationScreenTextYes) 

    let conformationScreenTextNo = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextNo.text = "No" 
    conformationScreenTextNo.fontSize = 150 
    conformationScreenTextNo.fontColor = SKColor.red 
    conformationScreenTextNo.position = CGPoint(x: self.size.width*0.70, y: self.size.height*0.30) 
    conformationScreenTextNo.zPosition = 3 
    self.addChild(conformationScreenTextNo) 


} 



override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 

    for touch: AnyObject in touches{ 

     let pointOfTouch = touch.location(in: self) 
     let tappedNode = atPoint(pointOfTouch) 
     let tappedNodeName = tappedNode.name 


     if tappedNodeName == "nextShipClick"{ 

      let sceneToMoveTo = ShopPage2(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 

     if tappedNodeName == "backToMainMenuButton"{ 

      let sceneToMoveTo = MainMenuScene(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 




    } 

} 

} 
+1

여기에있는 질문은 무엇이며 문제는 무엇입니까? 그런데 당신의 전문은 잘못되었습니다. 장면에 하위 뷰를 추가하지 마십시오. 노드를 추가합니다. UIKit에서는 하위 뷰를 다른 뷰에 추가합니다. – Whirlwind

답변

0

내가 가진 : 당신이 버튼을 누를 때

그래서, 당신은 단순히보다 현실적인 이러한 조치가의 당신이 좋아하는 어떤 애니메이션을 사용할 수 있습니다하려면 1로 가장 높은 값으로 zPositionalpha 변경 모양새 화면을 작동시키는 방법을 알아 냈습니다. 모든 도움을 주신 @AlessandroOrnano에게 감사드립니다! 나중에 참조 할 수 있도록 아래 코드를 첨부했습니다. 누구든지이 일을하는보다 효율적인 방법이 있다면 나는 어떤 제안이라도 대단히 감사 할 것입니다.

import Foundation 
import SpriteKit 


let shipForSale = SKSpriteNode(imageNamed: "playerShip4") 

class ShopPage1ConformationScreen: SKScene{ 


override func didMove(to view: SKView) { 

    let background = SKSpriteNode(imageNamed: "background") 
    background.position = CGPoint(x: self.size.width/2, y: self.size.height/2) 
    background.zPosition = 0 
    self.addChild(background) 

    let balance = SKLabelNode(fontNamed: "The Bold Font") 
    balance.text = "$\(balanceAmount)" 
    balance.fontSize = 100 
    balance.fontColor = SKColor.green 
    balance.position = CGPoint(x: self.size.width/2, y: self.size.height*0.87) 
    balance.zPosition = 1 
    self.addChild(balance) 

    let backToMainMenuButton = SKSpriteNode(imageNamed: "backButton2") 
    backToMainMenuButton.position = CGPoint(x: self.size.width*0.25, y: self.size.height*0.89) 
    backToMainMenuButton.zPosition = 1 
    backToMainMenuButton.size = CGSize(width: 200, height: 200) 
    backToMainMenuButton.name = "backToMainMenuButton" 
    self.addChild(backToMainMenuButton) 

    let shipNameLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipNameLabel.text = "Stealth" 
    shipNameLabel.fontSize = 200 
    shipNameLabel.fontColor = SKColor.white 
    shipNameLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.60) 
    shipNameLabel.zPosition = 1 
    shipNameLabel.name = "shipNameLabel" 
    self.addChild(shipNameLabel) 

    let nextShipButton = SKSpriteNode(imageNamed: "nextShipButton1") 
    nextShipButton.position = CGPoint(x: self.size.width*0.75, y: self.size.height*0.40) 
    nextShipButton.zPosition = 1 
    nextShipButton.size = CGSize(width: 300, height: 300) 
    nextShipButton.name = "nextShipButton" 
    self.addChild(nextShipButton) 


    let nextShipClick = SKLabelNode(fontNamed: "The Bold Font") 
    nextShipClick.text = "▲" 
    nextShipClick.fontSize = 300 
    nextShipClick.fontColor = UIColor.clear 
    nextShipClick.position = CGPoint(x: self.size.width*0.753, y: self.size.height*0.36) 
    nextShipClick.zPosition = 2 
    nextShipClick.name = "nextShipClick" 
    self.addChild(nextShipClick) 



    shipForSale.position = CGPoint(x: self.size.width/2, y: self.size.height*0.40) 
    shipForSale.zPosition = 1 
    shipForSale.size = CGSize(width: 150, height: 300) 
    self.addChild(shipForSale) 

    let shipPodium = SKSpriteNode(imageNamed: "shipPodium") 
    shipPodium.position = CGPoint(x: self.size.width*0.527, y: self.size.height*0.31) 
    shipPodium.zPosition = 1 
    shipPodium.size = CGSize(width: 1200, height: 70) 
    self.addChild(shipPodium) 

    let shipsCostLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipsCostLabel.text = "$500" 
    shipsCostLabel.fontSize = 200 
    shipsCostLabel.fontColor = SKColor.white 
    shipsCostLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.20) 
    shipsCostLabel.zPosition = 1 
    self.addChild(shipsCostLabel) 

    let shipBuyButton = SKSpriteNode(imageNamed: "shipBuyButton") 
    shipBuyButton.position = CGPoint(x: self.size.width*0.54, y: self.size.height*0.15) 
    shipBuyButton.zPosition = 1 
    shipBuyButton.size = CGSize(width: 1500, height: 900) 
    shipBuyButton.name = "shipBuyButton" 
    self.addChild(shipBuyButton) 

    let conformationBackground = SKSpriteNode(imageNamed: "conformationBackground") 
    conformationBackground.position = CGPoint(x: self.size.width*0.51, y: self.size.height*0.40) 
    conformationBackground.zPosition = 2 
    conformationBackground.size = CGSize(width: 1300, height: 1400) 
    conformationBackground.name = "conformationBackground" 
    self.addChild(conformationBackground) 

    let conformationScreenTextTop = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextTop.text = "Are you sure you wish to" 
    conformationScreenTextTop.fontSize = 80 
    conformationScreenTextTop.fontColor = SKColor.white 
    conformationScreenTextTop.position = CGPoint(x: self.size.width/2, y: self.size.height*0.46) 
    conformationScreenTextTop.zPosition = 3 
    conformationScreenTextTop.name = "comformationScreenTextTop" 
    self.addChild(conformationScreenTextTop) 

    let conformationScreenTextBottom = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextBottom.text = "purchase this ship?" 
    conformationScreenTextBottom.fontSize = 80 
    conformationScreenTextBottom.fontColor = SKColor.white 
    conformationScreenTextBottom.position = CGPoint(x: self.size.width/2, y: self.size.height*0.41) 
    conformationScreenTextBottom.zPosition = 3 
    conformationScreenTextBottom.name = "conformationScreenTextBottom" 
    self.addChild(conformationScreenTextBottom) 

    let conformationScreenTextYes = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextYes.text = "Yes" 
    conformationScreenTextYes.fontSize = 150 
    conformationScreenTextYes.fontColor = SKColor.green 
    conformationScreenTextYes.position = CGPoint(x: self.size.width*0.30, y: self.size.height*0.30) 
    conformationScreenTextYes.zPosition = 3 
    conformationScreenTextYes.name = "conformationScreenTextYes" 
    self.addChild(conformationScreenTextYes) 

    let conformationScreenTextNo = SKLabelNode(fontNamed: "The Bold Font") 
    conformationScreenTextNo.text = "No" 
    conformationScreenTextNo.fontSize = 150 
    conformationScreenTextNo.fontColor = SKColor.red 
    conformationScreenTextNo.position = CGPoint(x: self.size.width*0.70, y: self.size.height*0.30) 
    conformationScreenTextNo.zPosition = 3 
    conformationScreenTextNo.name = "conformationScreenTextNo" 
    self.addChild(conformationScreenTextNo) 
} 


override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 

    for touch: AnyObject in touches{ 

     let pointOfTouch = touch.location(in: self) 
     let tappedNode = atPoint(pointOfTouch) 
     let tappedNodeName = tappedNode.name 

     if(balanceAmount >= 500){ 
     if tappedNodeName == "conformationScreenTextYes"{ 
      player = shipForSale 
      balanceAmount -= 500 
      let sceneToMoveTo = ShopPage1(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 
     } 

     if tappedNodeName == "conformationScreenTextNo"{ 
      let sceneToMoveTo = ShopPage1(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 



    } 
} 
} 

추가 상점 페이지 만 복사 코드의이 세트를 붙여 넣기 :

import Foundation 
import SpriteKit 

class ShopPage1: SKScene{ 


override func didMove(to view: SKView) { 

    let background = SKSpriteNode(imageNamed: "background") 
    background.position = CGPoint(x: self.size.width/2, y: self.size.height/2) 
    background.zPosition = 0 
    self.addChild(background) 

    let balance = SKLabelNode(fontNamed: "The Bold Font") 
    balance.text = "$\(balanceAmount)" 
    balance.fontSize = 100 
    balance.fontColor = SKColor.green 
    balance.position = CGPoint(x: self.size.width/2, y: self.size.height*0.87) 
    balance.zPosition = 1 
    self.addChild(balance) 

    let backToMainMenuButton = SKSpriteNode(imageNamed: "backButton2") 
    backToMainMenuButton.position = CGPoint(x: self.size.width*0.25, y: self.size.height*0.89) 
    backToMainMenuButton.zPosition = 1 
    backToMainMenuButton.size = CGSize(width: 200, height: 200) 
    backToMainMenuButton.name = "backToMainMenuButton" 
    self.addChild(backToMainMenuButton) 

    let shipNameLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipNameLabel.text = "Stealth" 
    shipNameLabel.fontSize = 200 
    shipNameLabel.fontColor = SKColor.white 
    shipNameLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.60) 
    shipNameLabel.zPosition = 1 
    shipNameLabel.name = "shipNameLabel" 
    self.addChild(shipNameLabel) 

    let nextShipButton = SKSpriteNode(imageNamed: "nextShipButton1") 
    nextShipButton.position = CGPoint(x: self.size.width*0.75, y: self.size.height*0.40) 
    nextShipButton.zPosition = 1 
    nextShipButton.size = CGSize(width: 300, height: 300) 
    nextShipButton.name = "nextShipButton" 
    self.addChild(nextShipButton) 


    let nextShipClick = SKLabelNode(fontNamed: "The Bold Font") 
    nextShipClick.text = "▲" 
    nextShipClick.fontSize = 300 
    nextShipClick.fontColor = UIColor.clear 
    nextShipClick.position = CGPoint(x: self.size.width*0.753, y: self.size.height*0.36) 
    nextShipClick.zPosition = 2 
    nextShipClick.name = "nextShipClick" 
    self.addChild(nextShipClick) 


    let shipForSale = SKSpriteNode(imageNamed: "playerShip4") 
    shipForSale.position = CGPoint(x: self.size.width/2, y: self.size.height*0.40) 
    shipForSale.zPosition = 1 
    shipForSale.size = CGSize(width: 150, height: 300) 
    self.addChild(shipForSale) 

    let shipPodium = SKSpriteNode(imageNamed: "shipPodium") 
    shipPodium.position = CGPoint(x: self.size.width*0.527, y: self.size.height*0.31) 
    shipPodium.zPosition = 1 
    shipPodium.size = CGSize(width: 1200, height: 70) 
    self.addChild(shipPodium) 

    let shipsCostLabel = SKLabelNode(fontNamed: "The Bold Font") 
    shipsCostLabel.text = "$500" 
    shipsCostLabel.fontSize = 200 
    shipsCostLabel.fontColor = SKColor.white 
    shipsCostLabel.position = CGPoint(x: self.size.width/2, y: self.size.height*0.20) 
    shipsCostLabel.zPosition = 1 
    self.addChild(shipsCostLabel) 

    let shipBuyButton = SKSpriteNode(imageNamed: "shipBuyButton") 
    shipBuyButton.position = CGPoint(x: self.size.width*0.54, y: self.size.height*0.15) 
    shipBuyButton.zPosition = 1 
    shipBuyButton.size = CGSize(width: 1500, height: 900) 
    shipBuyButton.name = "shipBuyButton" 
    self.addChild(shipBuyButton) 

    let shipBuyButtonClick = SKLabelNode(fontNamed: "The Bold Font") 
    shipBuyButtonClick.text = "▅▅" 
    shipBuyButtonClick.fontSize = 300 
    shipBuyButtonClick.fontColor = UIColor.clear 
    shipBuyButtonClick.position = CGPoint(x: self.size.width/2, y: self.size.height*0.05) 
    shipBuyButtonClick.zPosition = 2 
    shipBuyButtonClick.name = "shipBuyButtonClick" 
    self.addChild(shipBuyButtonClick) 

} 



override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 

    for touch: AnyObject in touches{ 

     let pointOfTouch = touch.location(in: self) 
     let tappedNode = atPoint(pointOfTouch) 
     let tappedNodeName = tappedNode.name 


     if tappedNodeName == "nextShipClick"{ 

      let sceneToMoveTo = ShopPage2(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 

     if tappedNodeName == "backToMainMenuButton"{ 

      let sceneToMoveTo = MainMenuScene(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
     } 

     if tappedNodeName == "shipBuyButtonClick"{ 

      let sceneToMoveTo = ShopPage1ConformationScreen(size: self.size) 
      sceneToMoveTo.scaleMode = self.scaleMode 
      let myTransition = SKTransition.fade(withDuration: 0.5) 
      self.view!.presentScene(sceneToMoveTo, transition: myTransition) 
      } 

    } 

} 

} 

는 ShopPage1ConformationScreen 코드입니다. 탭된 노드를 페이지간에 이동하려는 올바른 순서로 변경하는 것을 제외하고는.

0

회오리 바람이 당신의 장면의 중심에 SKNode를 만들 수 있습니다 자신의 의견에 말했듯이 (위치 CGPoint.zero) :

이 내 코드는 지금까지 모습입니다 alpha 속성을 0으로 설정하고 zPosition을 -1로 설정합니다 (장면의 다른 모든 보이는 노드 아래에 있음).

extension UIView { 
    func fadeIn(_ duration:TimeInterval=1.0) { 
     UIView.animate(withDuration: duration, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: { 
      self.alpha = 1.0 // Instead of a specific instance of, say, birdTypeLabel, we simply set [thisInstance] (ie, self)'s alpha 
     }, completion: nil) 
    } 
    func fadeOut(_ duration:TimeInterval=1.0) { 
     UIView.animate(withDuration: duration, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { 
      self.alpha = 0.0 
     }, completion: nil) 
    } 
} 
+0

노드에 이러한 네 개의 스프라이트 노드와 레이블 노드를 추가하고 싶습니다. 어떻게해야할까요? conformationBackground, conformationScreenTextTop, conformationScreenTextBottom, conformationScreenTextNo – Jfost99

+0

당신이 말할 때 더 좋은 질문은 모든 것을 어떻게 준비 할까? – Jfost99

+1

@ Jfost99 제 생각에는이 코드를 "손에서"써야한다면 myNode = SKNode(); addChild (myNode); myNode.position = CGPoint.zero; myNode.zPosition = 1000 // myNode에 원하는 요소를 추가하십시오. 그런 다음이 대답에 설명되어있는 것보다 더 많은 것을 추가하지 마십시오. –