当前位置 : 主页 > 手机开发 > 其它 >

cocos2d-iphone – 在cocos2d中实现动画按钮

来源:互联网 收集:自由互联 发布时间:2021-06-13
我希望克隆在Candy Crush Saga中发现的按钮动画的效果. 而且我也想知道如何做这样的液体美丽的动画. 用Cocos2d-iPhone可以吗? 这是Candy Crush Sage的链接: http://www.youtube.com/watch?v=KAMUWIqYN24 是
我希望克隆在Candy Crush Saga中发现的按钮动画的效果.
而且我也想知道如何做这样的液体&美丽的动画.
用Cocos2d-iPhone可以吗?

这是Candy Crush Sage的链接:

http://www.youtube.com/watch?v=KAMUWIqYN24

是用图像序列完成的吗?

有可能的.只需在按钮普通精灵上运行动画即可.

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 ];

//这是类文件:GTAnimSprite.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface GTAnimSprite : CCSprite
{
    bool bouncing;
    float counter;

}
@end

//这是类文件: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

这里是XCODE样本来源:https://www.box.com/s/52i4xyznetyyc329evcu

网友评论