想实现一个按钮,在未选中前进行重复的动画效果,试了下直接发代码吧:
bool MenuItemSpritTest::init()
{
//
// 1. super init first
if ( !Layer::init() )
{
return false;
}
//创建按钮精灵
Sprite* btn_normal_sprite=Sprite::create("menu_learn.png");
Sprite* btn_select_sprite=Sprite::create("menu_learn_select.png");
//通过sequence重复执行两个渐变动作
FadeTo* fadeto88=FadeTo::create(0.5, 88);
FadeTo* fadeto255=FadeTo::create(1, 255);
ActionInterval* fadeaction=Sequence::create(fadeto88,fadeto255,NULL);
btn_normal_sprite->runAction(RepeatForever::create(fadeaction));
MenuItemSprite* item1=MenuItemSprite::create(btn_normal_sprite, btn_select_sprite,nullptr,CC_CALLBACK_1(MenuItemSpritTest::select_learn,this));
Menu* menu1=Menu::create(item1,NULL);
menu1->setPosition(200,300);
this->addChild(menu1);
return true;
}
//回调函数
void MenuItemSpritTest::select_learn(Object* pSender){
log("You had selected learn button!");
}