1

I am developing a game using Sprite and the game works perfectly fine. I am trying to add in a feature that allows you to change things on that GameView. But the buttons for the feature are on a different ViewController. How would I be able to have the code be implemented into a different view controller?

This is the code i want the button to implement

        for touch: AnyObject in touches {
        // Get the location of the touch in this scene
        let location = touch.location(in: self)
        // Check if the location of the touch is within the button's bounds
        if button.contains(location) {
            Ghost.texture = SKTexture(imageNamed:"Ghost2")
        }
    }

And here is the button

@IBAction func button(_ sender: AnyObject) {

} But the button is on ViewController1 and the object that i want to change is on ViewController2 (GemScene)

Oren Edrich
  • 664
  • 1
  • 7
  • 23
  • you can use NSUserDefault (preference) to share info. – iO.S-C. Sep 27 '16 at 00:59
  • Possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – nbloqs Sep 27 '16 at 14:26

1 Answers1

1

Take a look to this question:

Passing Data between View Controllers (One of the answers shows Swift 3 syntax.)

Anyway, what I personally have done in these cases is to use NotificationCenter, which provides loosely coupled messages even between different ViewControllers. You can take a look here: NSNotifications in Swift 3

Community
  • 1
  • 1
nbloqs
  • 3,074
  • 1
  • 26
  • 47