- Home /
Question by
stephenjohnellis · Jul 24, 2014 at 04:01 AM ·
guitexturelayout
How to Assign variable textures using GUI Layout & Flexible Space
I'm working on building a memory game. I'm trying to create an image mosaic on the backs of the cards when they are not flipped over. The code I have is below. I know I need to create additional variables for the textures & grid locations, but I don't know enough about how GUI.layout is assigning those locations or how to assign the variable image textures. As is, I am only able to assign one image to each of the three state: matched, faceUp, flipped. I've attached an image of what I am trying to achieve.
Can someone please help!
Thanks.
function BuildGrid()
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
for(var i:int = 0; i<rows; i++)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
for(var j:int = 0; j<cols; j++)
{
var card:Card = aGrid[i,j];
var img:String;
if(card.isMatched)
{
img = "back";
}else{
if(card.isFaceUp)
{
img = card.img;
}else{
img = "Set1_Main";
}
}
if(GUILayout.Button(Resources.Load(img),GUILayout.Width(cardW),GUILayout.Height(cardH)))
{
if(playerCanClick)
{
FlipCardFaceUp(card);
}
Debug.Log(card.img);
}
}
GUI.enabled = true;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
class Card extends System.Object
{
var isFaceUp:boolean = false;
var isMatched:boolean = false;
var img:String;
var id:int;
function Card(img:String, id:int){
this.img = img;
this.id = id;
}
}
[1]: /storage/temp/29679-grid1.png
Comment