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).
精彩评论