ColorSwitch(类似于开关控件)
是由一堆精灵组成的
ControlSwitch* s = ControlSwitch::create(
Sprite::create("extensions/switch-mask.png"),//背景
Sprite::create("extensions/switch-on.png"),//开始
Sprite::create("extensions/switch-off.png"),//结束
Sprite::create("extensions/switch-thumb.png"),//按钮
Label::createWithSystemFont("On", "Arial", 16),
Label::createWithSystemFont("Off", "Arial", 16)
);
addChild(s);
s->setPosition(200,200);
/* 可以设置按钮回调函数 参数1是调用回调的控件,参数2是函数,参数3是事件类型*/
s->addTargetWithActionForControlEvents(this, (Control::Handler)(&T020701UI::Handler), Control::EventType::VALUE_CHANGED);
/*回调函数 参数1就是调用这个函数的控件,参数2 则是触发的事件类型,显然这个事件类型是某个专门的事件类中定义的*/
void Handler(Ref* sender, Control::EventType type)
{
ControlSwitch* s = (ControlSwitch*)sender;
CCLOG("called valueis %d", (int)s->isOn());
}
效果如下:
ColorSwitch(类似于开关控件)
是由一堆精灵组成的
ControlSwitch* s = ControlSwitch::create(