0

So I'm making a game, and in this game I need to have a certain sprite to appear multiple times.

It's simply an image, with two buttons. One button underneath the image, and one above.

I am using Cocos2d, so any mention of sprite will be the CCSprite class. And the image is actually just a line.

Is there an easy way to implement something like this? I don't want to have to make a separate sprite for the image, and then add each button. Is there a way I can do this all in one sprite?

I'm assuming that I'll probably have to manually add everything (create a method that will create an image and position the buttons relative to the image), but I'm hoping I'm wrong and there is an easier/more efficient way of doing this.

Thanks!

4

1 回答 1

1

我想你正在寻找CCMenuItemCCMenu

CCSprite *enabledSprite = [CCSprite spriteWithFile:@"myButtonSprite.png"];
CCSprite *selectedSprite = [CCSprite spriteWithFile:@"myButtonSprite.png"];
CCSprite *disabledSprite = [CCSprite spriteWithFile:@"myButtonSprite.png"];

CCMenuItemSprite *item [[[CCMenuItem alloc] initWithNormalSprite:enabledSprite 
                                                  selectedSprite:selectedSprite
                                                  disabledSprite:disabledSprite
                                                          target:delegate
                                                        selector:selector] autorelease];
item.position = ccp(240, 160);

CCMenu *menu = [CCMenu menuWithItems:item, nil];
menu.position = ccp(0, 0);
[self addChild:menu];
于 2012-06-14T09:44:25.680 回答