Tuesday, August 24, 2010

Week 7

When I open up the project folder I worked in class at home, I noticed that the buttons were spaced differently. When I played the game at max screen, the buttons during the pause menu suddenly crunch into each other. I don’t know whats wrong but tried tweaking the numbers and spacing variables a bit and it either spaced it too much or made it worst. I then realized the problem was the way I set up the buttons, do not scale probably with different resolution. If I test it out while the game window is small, it’ll look different when I play it on max screen. So the only other solution I could think of is using layouts.

GUILayout.BeginArea ();
GUILayout.EndArea ();

So implementing the script would be:

Function OnGUI ()
{

GUILayout.BeginArea();

If (GUILayout.Button(“Button 1”)
{
Print(“this button works”);
}
}

The difference with guilayout is that the buttons within the layout are clustered and organized nicely. If you apply a skin or style to the layout, it should affect everything within the layout, in theory or just the layout itself. This is how the gui.button would look like.

Function OnGUI()
{
If(Get.Button(Rect (0,0,0,0)))
{
Print(“this works also”)
}
}

Adding styles to the buttons within the layout was a bit tricky. I faced problems like warp/stretched buttons. I thought it would be the button so I kept tweaking the variable for button dimensions but it would not work the way I want after a few tries. I also had cases where only one button would show up , the rest or all will disappear, overstretch off to one end of the screen and all the other buttons will overlap. At first I think the layout box would be too small, so I tried enlarging the layout so all the buttons will be visible. I could only made the stretching worst. However, what baffle me the most is the first button did not have any negative effects from the new scripts.


function OnGUI()
{

if(Input.GetKey(KeyCode.Escape))
{
paused = true;
print("paused");
}


if(paused == true && startPrompt == true)
{

GUILayout.BeginArea (Rect(Screen.width/2 - 50, Screen.height/2 - 200, 1500, 1500));
Time.timeScale = 0.0;

GUILayout.Button("Menu", menu);

if(GUILayout.Button("Continue", continueStyle))
{
paused = false;
Time.timeScale = 1.0;
}

if(GUILayout.Button("Option", optionStyle))
{
print("This is Option Bitch!");
}

if(GUILayout.Button("redblue", redBlueStyle1))
{
varSwitch = 1;

if(switching == false && varSwitch == 1)
{
switching = true;
varSwitch = 0;
print("switching");
}

if(switching == true && varSwitch == 1)
{
switching = false;
varSwitch = 0;
print("not switching");
}

/*var toggleBoolNew = GUI.Toggle (Rect (25, 25, 100, 30), toggleBool, "Toggle");

// Check if the toggle was toggled
if (toggleBoolNew != toggleBool)
{
if (toggleBoolNew == true)
{
print("Toggle On");
}
else
{
print("Toggle off");
}
}*/
}

if(GUILayout.Button("A", aStyle))
{
print("die!!");
}

if(GUILayout.Button("B", bStyle))
{
print("B works");
}

GUILayout.EndArea ();
}


}


I couldn’t figure out why its stretching the buttons. I spent some times messing with various of variables with no positive results. I then noticed that the buttons been stretched way off to the side. So I look over my script carefully and wondered if the layout size is causing my button to stretch, which I don’t know why it would. So from here I changed the width of the layout to the buttonWidth.

function OnGUI()
{

if(Input.GetKey(KeyCode.Escape))
{
paused = true;
print("paused");
}


if(paused == true && startPrompt == true)
{

GUILayout.BeginArea (Rect(Screen.width/2 - 50, Screen.height/2 - 200, buttonWidth, 1500));


now the width of the buttons is corrected and looks good. from here, I added the box filter for the background and added texture to them.

No comments:

Post a Comment