加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 18:56:27 所属栏目:百科 来源:网络整理
导读:我希望克隆在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读