Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Last active December 19, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tks2shimizu/8d3fedbd56988b2ec37f to your computer and use it in GitHub Desktop.
Save tks2shimizu/8d3fedbd56988b2ec37f to your computer and use it in GitHub Desktop.
スイッチ
#include "HelloWorldScene.h"
USING_NS_CC;
USING_NS_CC_EXT;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCControlSwitch* switchCtrl = CCControlSwitch::create(CCSprite::create("extensions/switch-mask.png"),
CCSprite::create("extensions/switch-on.png"),
CCSprite::create("extensions/switch-off.png"),
CCSprite::create("extensions/switch-thumb.png"));
switchCtrl->setPosition(ccp(winSize.width / 2, winSize.height / 2));
switchCtrl->addTargetWithActionForControlEvents(this,
cccontrol_selector(HelloWorld::valueChanged),
CCControlEventValueChanged);
this->addChild(switchCtrl);
return true;
}
void HelloWorld::valueChanged(CCNode *pSender, CCControlEvent pControlEvent)
{
CCControlSwitch* pSwitch = (CCControlSwitch*)pSender;
if (pSwitch->isOn()) {
CCLog("valueChanged value: ON");
} else {
CCLog("valueChanged value: OFF");
}
}
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "CCControlExtensions.h"
class HelloWorld : public cocos2d::CCLayer
{
public:
virtual bool init();
static cocos2d::CCScene* scene();
void valueChanged(CCNode *pSender, cocos2d::extension::CCControlEvent pControlEvent);
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment