예제 #1
0
        //Instantiate the variables
        public static void Instantiate()
        {
            startButton = new Button();

            background = new Sprite();
        }
예제 #2
0
        /// <summary>
        /// Initialize the ButtonGroup
        /// </summary>
        public void Initialize(string[] texts, int xPosition)
        {
            //Instantiate all the buttons
            buttons = new Button[texts.Length];
            for (int i = 0; i < texts.Length; i++)
            {
                buttons[i] = new Button();
            }
            extraButtonBottem = new Button();
            extraButtonTop = new Button();

            //Initialize the currently selected button
            currentlySelected = 1;

            //Save the number of buttons in "buttonCount" variable
            buttonCount = texts.Length;

            //set the position on the x-axis for the buttons.
            this.xPosition = xPosition;

            ySpeed = 0;
            maxAcceleration = 3 / (float)buttonCount;

            //First the method checks if the amount of strings in the texts array is the same as the amount of buttons in the ButtonGroup
            if (texts.Length != buttonCount)
            {
                throw new Exception("The amount of strings in the \"texts\" variable is not the same as the amount of buttons in this group!");
            }

            //Initialize the arrays to the amount of buttons.
            positions = new float[buttonCount];
            this.texts = new string[buttonCount];
            float middlePosition = buttonCount / 2;

            //This code will repeat itself buttonCounts value times, and every value will be changed to the corresponding button.
            for (int i = 0; i < buttonCount; i++)
            {
                if ((float)i < (float)buttonCount / 2)
                {
                    positions[i] = middlePosition + (float)i;
                }
                else
                {
                    positions[i] = middlePosition - (float)(buttonCount - i);
                }
                this.texts[i] = texts[i];

                buttons[i].Initialize(this.texts[i]);
            }

            //The spacing between the buttons is the height of the screen (720 pixels) devided by the amount of buttons. This will make the first button at 0 pixels, and the last at 720 pixels)
            spacing = 720 / (buttonCount - 1);

            //Initializing the extra buttons for no other use than to avoid a error
            extraButtonBottem.Initialize("");
            extraButtonTop.Initialize("");
        }