Button 的create函数可以传入三个资源图片参数,第一个是初始的状况,第二个是点击时候的图片(如果为NULL,默认为变大),第三个是设置为不可用(Enable设置为false)的图片(如果为NULL,默认为显示为灰色)
Button* button = Button::create("green_block.png");
button->setName("button");
button->setTitleText("1");
button->setPosition(Point(100, 100));
this->addChild(button);
button->addClickEventListener(CC_CALLBACK_1(HelloWorld::Click,this));
void HelloWorld::Click(cocos2d::Ref * ref)
{
//Button* button = static_cast<Button *>(ref);
//button->setEnabled(false);
auto bird = static_cast<Sprite*>(getChildByName("bird"));
bird->stopAllActions();
int x = random(-50, 50);
int y = random(-50, 50);
MoveBy* moveby = MoveBy::create(1.2, Vec2(x, y));
//int z = random(0, 3);
if (x >= 0 && y < 0) {
z = 0;
}
if (x < 0 && y < 0) {
z = 1;
}
if (x >= 0 && y >= 0) {
z = 2;
}
if (x < 0 && y >= 0) {
z = 3;
}
Animation* animation = static_cast<Animation*>(anim_array->getObjectAtIndex(z));
Animate *animate = Animate::create(animation);
Repeat* repeat = Repeat::create(animate,3);
Spawn* spw = Spawn::create(moveby, repeat, NULL);
CallFunc* call = CallFunc::create(this, callfunc_selector(HelloWorld::callback));
Sequence* sq = Sequence::create(spw, call, NULL);
bird->runAction(sq);
}