Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created July 8, 2013 07:34
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/5a03938e0c3a34019b8d to your computer and use it in GitHub Desktop.
Save tks2shimizu/5a03938e0c3a34019b8d to your computer and use it in GitHub Desktop.
多機能なボタン
#include "HelloWorldScene.h"
#include "CCControlExtensions.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();
CCLabelTTF* label = CCLabelTTF::create("TAP ME\nTAP ME", "", 32);
CCScale9Sprite* sprite = CCScale9Sprite::create("controlbutton.png",
CCRectMake(0, 0, 100, 100),
CCRectMake(20, 20, 60, 60));
CCControlButton* button = CCControlButton::create(label, sprite);
button->addTargetWithActionForControlEvents(this,
cccontrol_selector(HelloWorld::buttonCallback),
CCControlEventTouchUpInside);
button->setPosition(ccp(winSize.width / 2, winSize.height / 2));
button->setTag(1);
this->addChild(button);
return true;
}
void HelloWorld::buttonCallback(CCNode* pSender)
{
CCLog("buttonTap tag: %d", pSender->getTag());
}
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.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