Button使用总结

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);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值