Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created July 10, 2013 02:38
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/6513cfe9a998fd156f52 to your computer and use it in GitHub Desktop.
Save tks2shimizu/6513cfe9a998fd156f52 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();
CCMenuItemImage *item1 = CCMenuItemImage::create("button_normal.png", "button_selected.png");
CCMenuItemImage *item2 = CCMenuItemImage::create("button_selected.png", "button_normal.png");
CCMenuItemToggle *toggle = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::buttonCallback),
item1, item2, NULL);
toggle->setPosition(ccp(winSize.width / 2, winSize.height / 2));
CCMenu *menu = CCMenu::create(toggle, NULL);
menu->setPosition(CCPointZero);
this->addChild(menu);
return true;
}
void HelloWorld::buttonCallback(CCNode *pSender)
{
CCLog("buttonTap selectedIndex: %d", ((CCMenuItemToggle*)pSender)->getSelectedIndex());
}
#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 buttonCallback(CCNode *pSender);
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