It is possible. Just run the animation on the buttons of a regular sprite.
GTAnimSprite *frame_normal = [GTAnimSprite spriteWithFile:@"play_button_normal.png"]; GTAnimSprite *frame_sel = [GTAnimSprite spriteWithFile:@"play_button_selected.png"]; frame_sel.color = ccc3(128,128,128); CCMenuItemSprite *plyBtn = [CCMenuItemSprite itemWithNormalSprite:frame_normal selectedSprite:frame_sel target:self selector:@selector(playBtnPress:) ]; plyBtn.position = ccp(size.width*0.77f, size.height*0.1f); CCMenu *menu2 = [CCMenu menuWithItems:plyBtn, nil]; menu2.position = ccp(0.0f,0.0f); [self addChild:menu2 z:2 ];
// Here is the class file: GTAnimSprite.h
#import <Foundation/Foundation.h> #import "cocos2d.h" @interface GTAnimSprite : CCSprite { bool bouncing; float counter; } @end
// Here is the class file: GTAnimSprite.mm
#import "GTAnimSprite.h" @implementation GTAnimSprite -(void)onEnter { [super onEnter]; counter = 0.0f; bouncing = true; [self scheduleUpdate]; } -(void)update:(ccTime)dt { if (bouncing) { counter += dt; self.scaleX = ( (sin(counter*10) + 1)/2.0 * 0.1 + 1); self.scaleY = ( (cos(counter*10) + 1)/2.0 * 0.1 + 1); if (counter > M_PI*10){ counter = 0; } } } -(void)onExit { [self unscheduleUpdate]; [super onExit]; } @end
HERE A SOURCE FOR USING XCODE: https://www.box.com/s/52i4xyznetyyc329evcu
source share