views:

59

answers:

1

Hi all Im just creating a menu for an iphone app using cocos2d CCMenuItem. Now i havent been using cocos2d that long so i may be doing this completely arse ways so hopefully someone can point me in the right direction.

CCMenuItem *mainMenuItem = [CCMenuItemImage itemFromNormalImage:@"Main Menu Up.png" selectedImage:@"Main Menu Down.png"
                                                                 target:self
                                                               selector:@selector(back:)];



CCMenu *soundMenu = [CCMenu menuWithItems:mainMenuItem, nil];

now this is fine and all works well but lets say i have a large amount of menu buttons to add do i have to add them all in this way or is it possible to create an nsmutablearray and add all the menu items to it and then add the array to soundmenu all in one go.

NSRange range = NSMakeRange(1, 10);
id *buffer = malloc(10 * sizeof(id));

CCMenu *soundMenu = [CCMenu menuWithItems:[myKeyboard getObjects:buffer range:range],nil];

like something like that? now of course this aint working for me im getting an invalid use of void expression error. Im not even sure its even possible to to do what i was trying so any tips would be greatly appreciated.

Also i need to create a custom keyboard using cocos2d if anyone has any tips or advice on that would be much appreciate. I havent really had much luck using google i keep getting code for using Interface Builder which im not a fan of. Is there a way of creating a keyboard just using cocos2d? Thanks all G

A: 

You don't have to do all that. Just create your CCMenuItems and then add all of them to the CCMenu in one line:

CCMenu *soundMenu = [CCMenu menuWithItems:mainMenuItem,anotherMenuItem, yetAnotherMenuItem, nil];

As for the keyboard part, i think you should search/open another question. Anyways, the simple way would be to add a UITextField view to the OpenGL view and let UIKit handle all the keyboard stuff.

The hard way would be to create your own keyboard with sprites and all, but you would have to handle all the showing/hiding, events, callbacks, etc. Of course you would get the benefit of better performance if done right.

pabloruiz55
yeah both of the ways you said is exactly what i ended up doing. I added all the menu items in the 1 line and created my own keyboard. it is using custom sprites so did end up amending what i needed from the menu.m and menuitem.m classes into new classes. seems to work well and lets me adjust how the keyboard reacts to interaction as i decide it to and now that its done the first time will be simple to reuse for future projects. thanks for getting back to me i just wanted to be sure that i was heading the right directionthanksG