微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我希望克隆在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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐