-
-
Save tks2shimizu/16c66c0811aef5c90833 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" | |
USING_NS_CC; | |
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* item = CCMenuItemImage::create("button_normal.png", | |
"button_selected.png", | |
this, | |
menu_selector(HelloWorld::buttonCallback)); | |
item->setPosition(ccp(winSize.width / 2, winSize.height / 2)); | |
item->setTag(1); | |
CCMenu* menu = CCMenu::create(item, NULL); | |
menu->setPosition(CCPointZero); | |
this->addChild(menu); | |
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