søndag 30. januar 2011

Creating a full game - the menu

A menu is often used at the beginning of a app. To start the game, to change the settings and other stuuf. But a menu can also be used as a controller for your character. It can be arrows to make your character move or a joystick. Here i will teach you how to make a menu with images. The code will be a little different if you make the menu with labels, which is just letters on the screen.
To make a menu, write this in your if statement in your init block:

//This first line adds a Image to the menu (mine is item1) itemFromNormalImage is what you want the picture to look like before you click it, and selected image is what you want the picture/button to look like when you click it (you can make these the same if you want to)

CCMenuItemImage *item1 = [CCMenuItemImage itemFromNormalImage:@"buttonplay.png" selectedImage:@"buttonplay2.png"

//target:self means look in the return self; class. selector:@selector is where the method is located, and doThis is just the name of the mathod that is going to be called whenever you click the button

target:self selector:@selector(doThis:)];


//CCMenu menu = menuwithitems: item1, nil means:
//The menu is named: menu, and these are the items i want in it. nil signifies the end of the //items

CCMenu *menu = [CCMenu menuWithItems:item1, nil];




 //self addChild means: add this menu to the scene, easily enough
[self addChild:menu];


CCMenuItemImage *item1 = [CCMenuItemImage itemFromNormalImage:@"buttonplay.png" selectedImage:@"buttonplay2.png" 
target:self selector:@selector(doThis:)];
CCMenu *menu = [CCMenu menuWithItems:item1, nil];
[self addChild:menu];

If you get any errors, please tell me. First time a made a menu i got a lot of errors.
Ex: i forgot to write @ before the filname.
Ex: i forgot ;

example of a menu          --->  ---> ---> ---> ---> ---> ---> ---> ---> --->   

Ingen kommentarer:

Legg inn en kommentar