Harin
Harin

Reputation: 867

On button clicked in cocos2d

I developed a small Child game in COCOs2d.

I used an image as a button in MenuItem. My problem is that when I click on the Menu Button I want to allow the image to look like selected image.

The code I used is as below :

CCMenuItem * blueCar = [CCMenuItemImage itemFromNormalImage:@"leftblueCar.png" selectedImage:@"blue-car.png" target:self selector:@selector(onSelectCar:)];

Upvotes: 4

Views: 667

Answers (2)

Muhammed Ayaz
Muhammed Ayaz

Reputation: 111

Add Layer on click Event and The Set image on it or do any thing What you want on new layer....

Upvotes: 1

phi
phi

Reputation: 10733

I'm not sure if you mean how to set a different image for a button when it is selected, but if this is the case you can use something like:

CCMenuItemImage *aButton = [CCMenuItemImage itemFromNormalImage:@"button_normal.png" selectedImage:@"button_selected.png" block:^(id sender){
  // Do something when user taps button
        }];

If you don't want to use blocks, you can use:

CCMenuItemImage *aButton = [CCMenuItemImage itemFromNormalImage:@"button_normal.png" selectedImage:@"button_selected.png" target:self selector:@selector(aButtonTapped:)];

Upvotes: 1

Related Questions