Tuesday, 26 June 2012

With the press of a button...

Alternating between different background colors was made possible by creating a variable called "buttonsPressed" using a conditional statement where if the button was pressed, the screen would turn black else it would remain the default red. Originally a ternary operator was used but was a bit more difficult to understand.

Here is a snippet of the code:

         public static void Update ()
        {
            // Query gamepad for current state
            var gamePadData = GamePad.GetData (0);

               if (gamePadData.Buttons != 0)
                buttonsPressed  = true;
            else
                buttonsPressed  = false;
              }

         public static void Render ()
         {
              // Clear the screen
              if (!buttonsPressed)
                  graphics.SetClearColor (1.0f, 0.0f, 0.0f, 0.0f);
              else
                  graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            
            graphics.Clear ();

In this video you can see the background color changing from default red to black and so forth. I am pressing CTRL on the keyboard which is the equivalent to any button on the PS Vita.

Warning: may cause small seizures




No comments:

Post a Comment