-
-
Save tks2shimizu/5a03938e0c3a34019b8d to your computer and use it in GitHub Desktop.
多機能なボタン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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