mardi 4 août 2015

Replay button doesn't work. (Swift, SpriteKit)

Once my game ends, it displays a button for replay, but I can't understand how to let Xcode know if there is a touch after the game has ended. My replay button's code is in didBeginContact Method and is as follows:

func didBeginContact(contact: SKPhysicsContact) {
       if (.....) {
            ..........
      }  else {
         replayButton = SKSpriteNode(imageNamed: "ReplayButton")
            replayButton.position = CGPoint(x: size.width / 1.75, y: size.height / 2.5)
            replayButton.name = "replayButton"
            self.addChild(replayButton)
       }

New Swift file:

class button: Mode {


override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

var touch = touches as!  Set<UITouch>
var location = touch.first!.locationInNode(self)
var node = self.nodeAtPoint(location)


if (node.name == "replayButton") {

    let myScene = EasyMode(size: self.size)
    myScene.scaleMode = scaleMode
    let reveal = SKTransition.fadeWithDuration(2.0)
    self.view?.presentScene(myScene, transition: reveal)
    }
  }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire