开发者

Cocos2d buttons running actions

开发者 https://www.devze.com 2023-03-23 06:03 出处:网络
Is it possible to create buttons in C开发者_如何学Pythonocos2d and run actions on them? e.g. some update code that then changes the image or runs an action?

Is it possible to create buttons in C开发者_如何学Pythonocos2d and run actions on them?

e.g. some update code that then changes the image or runs an action?

How does one do this?


Have a look at How To Create Buttons in Cocos2D: Simple, Radio, and Toggle.

This is a code snippet from the tutorial showing the basic:

CCMenuItem *starMenuItem = [CCMenuItemImage 
  itemFromNormalImage:@"ButtonStar.jpg" selectedImage:@"ButtonStarSel.jpg" 
  target:self selector:@selector(starButtonTapped:)];
starMenuItem.position = ccp(60, 60);
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];


the most common way is to create CCMenu with CCMenuItems as buttons. Within CCMenuItems you set action and images (normal, highlighted).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号