0

I apologise but I am relatively new to coding and venturing into typing up my own customisations of a flappy bird game. I have made two customisable buttons, for the bird and for the background. The bird button is fully functional but when the game runs and if I have clicked the background button on the main menu it has changed in the game but the button itself does not change on the main menu? Any help would be much appreciated, thank you!

import Foundation

class GameManager {

    static let instance = GameManager();
    private init() {}


    var birdIndex = Int(0);
    var birds = ["Blue", "Green", "Red"];


    func incrementIndex() {
        birdIndex += 1;
        if birdIndex == birds.count {
        birdIndex = 0
        }
    }

    func getBird() -> String {
        return birds[birdIndex];
    }



    var backIndex = Int(0);
    var backs = ["Day", "Night", "Preme"];

    func otherincrementIndex() {
        backIndex += 1;
        if backIndex == backs.count {
        backIndex = 0;
        }
    }

    func getBack() -> String {
        return backs[backIndex];
    }



    func setHighscore(highscore: Int) {
        UserDefaults.standard.set(highscore, forKey: "Highscore");
    }

    func getHighscore() -> Int {
        return UserDefaults.standard.integer(forKey: "Highscore");
    }

}

The customisable bird button does work but the background one doesn't. Is this problem going to be caused by this section or the Gameplay scene? Thank you again in advance.

  • Use the debugger and see why it crashes. But it seems obvious `backIndex` is out of range for the size of the array. – rmaddy Jan 04 '17 at 03:44
  • Just realised my mistake thank you so much I had written bird instead of back one place. The background is changing once in the game now, but the background button on the main menu still does not show this change? Would that be something wrong with the code I have posted here or will that be in my Gameplay Scene file? – user2733843 Jan 04 '17 at 03:50
  • That is going to be difficult to answer - use the debugger and step through your code as rmaddy suggests. – Yohst Jan 04 '17 at 04:31

0 Answers0