2017-03-05 83 views
1

在我的游戏的菜单:删除雪碧依然可点击

  1. 有一个框,用户可以点击。在第一阶段,这个盒子里只有一个“向导”精灵

  2. 当轻击/单击盒子或图像时,向导将被移除并替换为2个按钮,一个返回,一个返回确认。

  3. 我已经设置,所以我有一个变量(beenClicked2)被设置为0时,盒是在阶段1(或只是当向导子画面是在它)

  4. 当按压框,beenClicked2变量变为1,以便在阶段2中不能再次点击框并且不会崩溃。

  5. 然而,当盒只显示向导(stage1的)来自阶段2的返回按钮是仍然可点击这意味着盒不显示2个按钮,只是停留在阶段1

图片显示此: https://www.dropbox.com/s/st5fgv25fp3rz30/Image.png?dl=0

这里是我的代码:

//PURCHASING 
     if atPoint(location) == customBack2 || atPoint(location) == twoLivesWizard { 
      if lock1 == 0 && beenClicked2 == 0 { 
       twoLivesWizard.removeFromParent() 
       locked.removeFromParent() 
       self.addChild(purchaseText1) 
       self.addChild(purchaseTick1) 
       self.addChild(purchaseBack1) 

       beenClicked2 = 1 
       print("\(beenClicked2)") 
      } 
     } 

//Cancel Purchase 
     if atPoint(location) == purchaseBack1 { 
      beenClicked2 = 0 
      self.addChild(locked) 
      self.addChild(twoLivesWizard) 
      purchaseText1.removeFromParent() 
      purchaseTick1.removeFromParent() 
      purchaseBack1.removeFromParent() 

      print("\(beenClicked2)") 
     } 
+0

这里缺少信息。 1)哪个精灵仍然是可点击的(你在标题中提到过)? 2)尝试定义“点击错误的地方”? 3)你在说什么*框?尝试更精确地发布问题。帮助人们来帮助你。 – Whirlwind

+0

@Whirlwind嗨,对不起,不清楚。我已经更新了这个问题。希望这可以帮助! –

回答

1

下面是一个简单可行的例子,它可以可能给你一个线索在哪个方向,你可能会去:

import SpriteKit 

class GameScene: SKScene { 

    private let box = SKSpriteNode(color: .yellow, size: CGSize(width: 200, height: 300)) 

    private let wizard = SKSpriteNode(color: .purple, size: CGSize(width: 150, height: 250)) 
    private let back = SKSpriteNode(color: .gray, size: CGSize(width: 75, height: 75)) 
    private let confirm = SKSpriteNode(color: .lightGray, size: CGSize(width: 75, height: 75)) 

    private var stage = 0 

    override func didMove(to view: SKView) { 

     addChild(box) 
     box.addChild(wizard) 
     wizard.zPosition = 1 
     back.zPosition = 1 
     confirm.zPosition = 1 
     back.position.x = -50 
     confirm.position.x = 50 
    } 

    private func toggleStage(){ 

     if stage == 0 { 

      wizard.removeFromParent() 
      box.addChild(confirm) 
      box.addChild(back) 
      stage = 1 
     }else{ 

      confirm.removeFromParent() 
      back.removeFromParent() 
      box.addChild(wizard) 
      stage = 0 
     } 
    } 

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

     if let touch = touches.first { 

      let location = touch.location(in: self) 

      if stage == 0 { 

       if atPoint(location) == wizard { 
        toggleStage() 
       } 
      }else{ 
       if atPoint(location) == back { 
        print("Back button tapped") 
        toggleStage() 
       }else if atPoint(location) == confirm { 
        print("Confirm button tapped") 
       } 
      } 
     } 
    } 
} 

基本上,你需要做的是根据掉在舞台上的精灵。就我个人而言,我会自己创建一个名为Menu和Button的类,并在需要时执行委派。但那只是我。