Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created July 6, 2013 07:05
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/616e86ba8e4b17209932 to your computer and use it in GitHub Desktop.
Save tks2shimizu/616e86ba8e4b17209932 to your computer and use it in GitHub Desktop.
文字列のボタン
#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();
CCLabelTTF* label = CCLabelTTF::create("TAP ME", "Helvetica", 32);
CCMenuItemLabel* item = CCMenuItemLabel::create(label,
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());
}
#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