CCMenuitem Multi Line? - cocos2d-iphone

Is there a way to make a Menuitem multiline?
i tried
CCMenuItemFont mapPacks = [CCMenuItemFont itemFromString:#"Map\n Packs" target:self selector:#selector(mapPacks:)];
but that doesn`t seem to work

You forgot to add the '*' after CCMenuItemFont in your code snippet.
I use labels for creating multiline items, like this:
CCLabelTTF *label = [CCLabelTTF labelWithString:#"Map\n Packs" dimensions:CGSizeMake(100, 100)
alignment:UITextAlignmentCenter
fontName:#"Arial" fontSize:22];
CCMenuItemFont *mapPacks = [CCMenuItemFont itemWithLabel:label target:self selector:#selector(mapPacks:)];

Related

Scene Change Crash in cocos2d

I am having a problem when trying to push a button and going to the next scene. I get the SIGABRT error. I don't know what the problem is:
[...]
//Play Button
CCMenuItem *playbutton;
playbutton = [CCMenuItemFont itemWithString:#"Play" target:self selector:#selector(playButtonMeathod:)];
CMenu *menu = [CCMenu menuWithItems:itemAchievement,playbutton,itemLeaderboard, nil];
[menu alignItemsHorizontallyWithPadding:20];
[menu setPosition:ccp( size.width/2, size.height/2 - 50)];
// Add the menu to the layer
[self addChild:menu];
-(void)playButtonMeathod{
// Create a scene transition that uses the "RotoZoom" effect
CCTransitionRotoZoom *transition = [CCTransitionRotoZoom transitionWithDuration:1.0 scene:[Level_1 scene]];
// Tell the director to run the transition
[[CCDirector sharedDirector] replaceScene:transition];
[...]
One issue might be that the method signature is incorrect in your CCMenuItemFont selector target. Try:
CCMenuItemFont *playbutton = [CCMenuItemFont itemWithString:#"Play" target:self selector:#selector(playButtonMeathod)];

Cocos2d: CCMenu Buttons for Retina Devices Have small touchable area

For the project I'm working on I'm doing the following:
CCLabelBMFont *howtoplayGameLabelFont = [CCLabelBMFont labelWithString:#"HOW TO PLAY" fntFile:font];
[howtoplayGameLabelFont setFontsize:fontSize];
CCMenuItemLabel *howtoplayGameLabel = [CCMenuItemLabel itemWithLabel:howtoplayGameLabelFont target:self selector:#selector(startHowToPlay:)];
CCMenu *bottomMenu = [CCMenu menuWithItems:howtoplayGameLabel,creditsGameLabel, nil];
[bottomMenu alignItemsVerticallyWithPadding:padding];
[bottomMenu setPosition:ccp( size.width/2 + bottomXOffSet, size.height/2 + bottomYOffSet)];
[self addChild: bottomMenu z:10];
For non-retina displays the whole label is clickable, but for retina displays a really small section of the label is clickable.
How does one fix this?
Totally forgot I added code for setFontSize on CCMenuItemLabel. Here it is:
-(void)setFontsize:(float)fontsize
{
Fontsize_ = fontsize * CC_CONTENT_SCALE_FACTOR();
self.scale = (Fontsize_ / OriginalFontsize_);
}

Trying to make a menu with buttons; program crashes

The title is pretty self explanatory. I am currently trying to make a cocos2d menu and it compiles flawlessly however it crashes right before fully launching and my log reads this...
+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
I don't know what this means here is my code though
// Standard method to create a button
CCMenuItem *Earth = [CCMenuItemImage itemFromNormalImage:#"1.png"
selectedImage:#"1.png"
target:self
selector:#selector(loadLevel:)];
Earth.position = ccp(160, 0);
CCMenuItem *Mars = [CCMenuItemImage itemFromNormalImage:#"2.png"
selectedImage:#"2.png"
target:self
selector:#selector(loadLevel:)];
Mars.position = ccp(160, 240);
CCMenuItem *Moon = [CCMenuItemImage itemFromNormalImage:#"3.png"
selectedImage:#"3.png"
target:self
selector:#selector(loadLevel:)];
Moon.position = ccp(160, 480);
CCMenu *myMenu = [CCMenu menuWithItems:Earth, Mars,Moon, nil];
[myMenu setPosition:ccp(160,240)];
[self addChild:myMenu z:0];
After adding this my program began to crash. Thanks for any help guys you are the best.
you need to implement loadLevel like this
-(void) loadLevel:(NSObject*) sender
{
}

how to pop a layer in cocos2d

please look the following picture
i want to do this function,when i click some button,it pop out a layer
my code is
-(id)init{
if (self = [super init]) {
CCMenuItem *successbtn = [CCMenuItemImage itemFromNormalImage:#"success.png"
selectedImage:#"success.png"
target:self
selector:#selector(successgame:)];
CCMenu *ccMenu = [CCMenu menuWithItems:successbtn, nil];
ccMenu.position=ccp(950,700);
[self addChild:ccMenu z:1 tag:2];
}
return self;
}
-(void)successgame:(id)sender{
//how can i write here?
}
so how can i write?
There is two possibilities. Either just add the button when you really want to show it and remove it from the Scenegraph as soon as it is not needed anymore.
Alternatively just make it invisible with the visible-property.

CCLabelBMFont for a menu item?

Hey I am crazy stuck on this. I want to use my cool heiro font sheet i got the CCLabelBMFont working great as labels and score variables but can't get them into the menu as clickable items! but it the CCLabelMBFont says specifically that you can use them as menu items -- see here:
Detailed Description
CCLabelBMFont is a subclass of CCSpriteBatchNode
Features:
* Treats each character like a CCSprite. This means that each individual character can be:
o rotated
o scaled
o translated
o tinted
o chage the opacity
* It can be used as part of a menu item.
* anchorPoint can be used to align the "label"
* Supports AngelCode text format
Yet i've looked all over the web and can't find one example of anybody getting a CCLabelBMFont as a menu item. Here's the code I have so far:
-(id) init
{
if( (self=[super init] )) {
CCLabelBMFont *homeTest = [CCLabelBMFont labelWithString:#"HomeTEST" fntFile:#"hieroTitle2.fnt"];
homeTest.position = ccp(0, 0);
//finalScoreFont.position = ccp(wrapper.position.x, wrapper.position.y-40);
[self addChild:homeTest z:2 tag:kTagHomeTest];
/* here's where I am lost and want to put the CCLabelBMFont
CCMenuItem *homeButton =
home.position = ccp(0, 0);
CCMenu *menu = [CCMenu menuWithItems:homeButton, nil];
menu.position = ccp(60, 50);
*/
[self addChild:menu z:3];
}
return self;
}
i found a clue and possible solution! Check out this guys code:
CCLabelBMFont *tlabel = [CCLabelBMFont labelWithString:#"Page 2" fntFile:#"customfont.fnt"];
CCMenuItemLabel *titem = [CCMenuItemLabel itemWithLabel:tlabel target:self selector:#selector(testCallback:)];
CCMenu *menu = [CCMenu menuWithItems: titem, nil];
menu.position = ccp(screenSize.width/2, screenSize.height/2);
Nice! he first makes the label and then uses that CCLabelBMFont as the CCMenuItemLabel Weeee! I would have never figured that out. I'm going to try it