Buttons in tiled

This topic contains 5 replies, has 3 voices, and was last updated by  LaneStevens 2 years, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
Author Posts
Author Posts
December 3, 2011 at 7:25 pm #237425

LaneStevens
@lanestevens

Im trying to make a button in my tiled game like the one in

http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

like a button in the middle of the level just to do something like say hello so i dont want it in the HUD i want it in the level, so i made the button

noButton = [CCMenuItemImage itemFromNormalImage:@"NoButton.png" selectedImage:@"NoButton.png" target:self selector:@selector(doTheAction)];
noButton.position = ccp(xNoButton, yNoButton);
noButton.scale = .5;
[self addChild:noButton z:3];

Then i have the @selector

-(void)doTheAction {

NSLog("You pressed NOBUTTON");

}

but when i press the button it does nothing, just moves the player.

Any tips

sorry for the noobishness just came back to cocos2d

December 3, 2011 at 9:10 pm #357540

itlgames
Moderator
@itlgames

You should see a warning when compiling in XCode 4/iOS 5:

Passing argument 1 of 'NSLog' from incompatible pointer type

Or an error in XCode 3/iOS4:

error: cannot convert 'const char*' to 'NSString*' for argument '1' to 'void NSLog(NSString*, ...)'

Try using:

NSLog(@"You pressed NOBUTTON");

December 3, 2011 at 9:22 pm #357541

LaneStevens
@lanestevens

im sorry, i accidently left that part of my code out and when i typed i typed it up on here, the actual code is NSLog(@”You pressed NOBUTTON”);

im sorry i left that out

December 4, 2011 at 4:46 am #357542

skyhawk
Participant
@skyhawk

Add menu items to menu?

December 6, 2011 at 3:22 am #357543

LaneStevens
@lanestevens

ok i have tested and tested still nothing, i tried

yesButton = [CCMenuItemImage itemFromNormalImage:@"YesButton.png" selectedImage:@"YesButton.png" target:self selector:@selector(yesSellCrops)];
yesButton.position = ccp(xYesButton, yYesButton);
yesButton.scale = .5;
[self addChild:yesButton z:3];

//No Button
noButton = [CCMenuItemImage itemFromNormalImage:@"NoButton.png" selectedImage:@"NoButton.png" target:self selector:@selector(noSellCrops)];
noButton.position = ccp(xNoButton, yNoButton);
noButton.scale = .5;
[self addChild:noButton z:3];

the buttons then show up, but don’t work .

I try

yesButton = [CCMenuItemImage itemFromNormalImage:@"YesButton.png" selectedImage:@"YesButton.png" target:self selector:@selector(yesSellCrops)];
yesButton.position = ccp(xYesButton, yYesButton);
yesButton.scale = .5;
[self addChild:yesButton z:3];

//No Button
noButton = [CCMenuItemImage itemFromNormalImage:@"NoButton.png" selectedImage:@"NoButton.png" target:self selector:@selector(noSellCrops)];
noButton.position = ccp(xNoButton, yNoButton);
noButton.scale = .5;
[self addChild:noButton z:3];

CCMenu *menuTest = [CCMenu menuWithItems:yesButton, noButton, nil];
[self addChild:menuTest z:3];

I get an error then i realise i add the menu as a child with the buttons so i don’t have to do that, so i remove that

yesButton = [CCMenuItemImage itemFromNormalImage:@"YesButton.png" selectedImage:@"YesButton.png" target:self selector:@selector(yesSellCrops)];
yesButton.position = ccp(xYesButton, yYesButton);
yesButton.scale = .5;

//No Button
noButton = [CCMenuItemImage itemFromNormalImage:@"NoButton.png" selectedImage:@"NoButton.png" target:self selector:@selector(noSellCrops)];
noButton.position = ccp(xNoButton, yNoButton);
noButton.scale = .5;

CCMenu *menuTest = [CCMenu menuWithItems:yesButton, noButton, nil];
[self addChild:menuTest z:3];

and the buttons do not show up. Can you help? im sorry im get frustrated.

Thanks

December 11, 2011 at 11:41 pm #357544

LaneStevens
@lanestevens

bump

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.