Reputation: 6551
I saw a really great post about making a Button class for use in Cocos2d: http://johnehartzog.com/2009/10/easy-to-create-buttons-with-cocos2d/
I love the idea because it really simplifies button creation, but he seems to be using an older version of Cocos2d and I can't get his code working.
@interface Button : Menu { // !Cannot find interface declaration for 'Menu', superclass of Button
}
+ (id)buttonWithText:(NSString*)text atPosition:(CGPoint)position target:(id)target selector:(SEL)selector;
+ (id)buttonWithImage:(NSString*)file atPosition:(CGPoint)position target:(id)target selector:(SEL)selector;
@end
@interface ButtonItem : MenuItem { // !Cannot find interface declaration for 'MenuItem'...
Sprite *back; // !Unknown type name Sprite
Sprite *backPressed;
}
+ (id)buttonWithText:(NSString*)text target:(id)target selector:(SEL)selector;
+ (id)buttonWithImage:(NSString*)file target:(id)target selector:(SEL)selector;
- (id)initWithText:(NSString*)text target:(id)target selector:(SEL)selector;
- (id)initWithImage:(NSString*)file target:(id)target selector:(SEL)selector;
@end
Changing everything to CCMenu, CCSprite doesn't solve the problem. There are also a lot of related errors in Button.m
Is there any code similar to this that works with Cocos2d 2.0 for making simple buttons? Or am I missing something obvious?
Upvotes: 0
Views: 806
Reputation: 1578
Backwards compatibility between different versions of Cocos2d is a tricky task. Might I recommend using cocosbuilder for creating menus? It has about an hour or so learning curve, but will save you many more hours down the road.
Upvotes: 3