开发者

Cocos2d buttons running actions

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜