使用cocos2d-x使切换菜单项成为滑动(开/关)按钮

使用cocos2d-x使切换菜单项成为滑动(开/关)按钮,cocos2d-x,togglebutton,Cocos2d X,Togglebutton,在使用cocos2d-x时遇到了一个问题。切换菜单用于声音和音乐开关。我想让它们像苹果的原生用户界面一样可以拖动。在网上甚至论坛和文档中搜索。我想你要找的是CCControlSwitch CCSprite *onSprite = CCSprite::create("ui/switch-on.png"); CCSprite *offSprite = CCSprite::create("ui/switch-off.png"); CCSprite *thumbSprite = CCSprite::cr

在使用cocos2d-x时遇到了一个问题。切换菜单用于声音和音乐开关。我想让它们像苹果的原生用户界面一样可以拖动。在网上甚至论坛和文档中搜索。

我想你要找的是CCControlSwitch

CCSprite *onSprite = CCSprite::create("ui/switch-on.png");
CCSprite *offSprite = CCSprite::create("ui/switch-off.png");
CCSprite *thumbSprite = CCSprite::create("ui/switch-thumb.png");
CCSprite *maskSprite = CCSprite::create("ui/switch-mask.png");

CCControlSwitch *control = CCControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, nullptr, nullptr);
control->setOn(status);
control->needsLayout();
control->addTargetWithActionForControlEvents(this, cccontrol_selector(DebugLayer::toggleShowStats),, CCControlEventValueChanged);
addChild(control);

cocos2dx发行版中的samples/Cpp/TestCpp/Classes/extensiontest/ControlExtensionTest中有一个示例

希望有帮助,
Laurent我想你要找的是CCControlSwitch

CCSprite *onSprite = CCSprite::create("ui/switch-on.png");
CCSprite *offSprite = CCSprite::create("ui/switch-off.png");
CCSprite *thumbSprite = CCSprite::create("ui/switch-thumb.png");
CCSprite *maskSprite = CCSprite::create("ui/switch-mask.png");

CCControlSwitch *control = CCControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, nullptr, nullptr);
control->setOn(status);
control->needsLayout();
control->addTargetWithActionForControlEvents(this, cccontrol_selector(DebugLayer::toggleShowStats),, CCControlEventValueChanged);
addChild(control);

cocos2dx发行版中的samples/Cpp/TestCpp/Classes/extensiontest/ControlExtensionTest中有一个示例

希望有帮助,
Laurent我想你要找的是CCControlSwitch

CCSprite *onSprite = CCSprite::create("ui/switch-on.png");
CCSprite *offSprite = CCSprite::create("ui/switch-off.png");
CCSprite *thumbSprite = CCSprite::create("ui/switch-thumb.png");
CCSprite *maskSprite = CCSprite::create("ui/switch-mask.png");

CCControlSwitch *control = CCControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, nullptr, nullptr);
control->setOn(status);
control->needsLayout();
control->addTargetWithActionForControlEvents(this, cccontrol_selector(DebugLayer::toggleShowStats),, CCControlEventValueChanged);
addChild(control);

cocos2dx发行版中的samples/Cpp/TestCpp/Classes/extensiontest/ControlExtensionTest中有一个示例

希望有帮助,
Laurent我想你要找的是CCControlSwitch

CCSprite *onSprite = CCSprite::create("ui/switch-on.png");
CCSprite *offSprite = CCSprite::create("ui/switch-off.png");
CCSprite *thumbSprite = CCSprite::create("ui/switch-thumb.png");
CCSprite *maskSprite = CCSprite::create("ui/switch-mask.png");

CCControlSwitch *control = CCControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, nullptr, nullptr);
control->setOn(status);
control->needsLayout();
control->addTargetWithActionForControlEvents(this, cccontrol_selector(DebugLayer::toggleShowStats),, CCControlEventValueChanged);
addChild(control);

cocos2dx发行版中的samples/Cpp/TestCpp/Classes/extensiontest/ControlExtensionTest中有一个示例

希望有帮助,
Laurent

你的意思是你想要一个(开|关)滑动按钮,就像设置应用程序中的许多项目一样?如果你想设置按钮更改的动画,你必须对其进行自定义编码,但不能使用CCMenuItem(除非你相应地对其进行成本计算)。是的,这就是我想要做的。但我也想用它作为切换菜单按钮。。。就像任何iOS设备的seetings选项一样,你是说你想要一个(开|关)滑动按钮,就像设置应用程序中的许多项目一样?如果你想设置按钮更改的动画,你必须对其进行自定义编码,但不能使用CCMenuItem(除非你相应地对其进行成本计算)。是的,这就是我想要做的。但我也想用它作为切换菜单按钮。。。就像任何iOS设备的seetings选项一样,你是说你想要一个(开|关)滑动按钮,就像设置应用程序中的许多项目一样?如果你想设置按钮更改的动画,你必须对其进行自定义编码,但不能使用CCMenuItem(除非你相应地对其进行成本计算)。是的,这就是我想要做的。但我也想用它作为切换菜单按钮。。。就像任何iOS设备的seetings选项一样,你是说你想要一个(开|关)滑动按钮,就像设置应用程序中的许多项目一样?如果你想设置按钮更改的动画,你必须对其进行自定义编码,但不能使用CCMenuItem(除非你相应地对其进行成本计算)。是的,这就是我想要做的。但我也想用它作为切换菜单按钮。。。与任何iOS设备的seetings选项类似