#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
USING_NS_CC;
class HelloWorld : public cocos2d::CCLayer
{
public:
virtual bool init();
static cocos2d::CCScene* scene();
void menuCloseCallback(CCObject* pSender);
CREATE_FUNC(HelloWorld);
//touch
private:
virtual void registerWithTouchDispatcher(void);
virtual void ccTouchesBegan(CCSet * set,CCEvent * e);
virtual void ccTouchesMoved(CCSet * set,CCEvent * e);
virtual void ccTouchesEnded(CCSet * set,CCEvent * e);
//写上生命周期函数
virtual void onEnter();
virtual void onExit();
};
#endif // __HELLOWORLD_SCENE_H__
#include "HelloWorldScene.h"
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
this->setTouchEnabled(true);
return true;
}
void HelloWorld::registerWithTouchDispatcher(void){
//注册监听
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
}
void HelloWorld::ccTouchesBegan(CCSet * set,CCEvent * e)
{
CCLOG("hello begin");
}
void HelloWorld::ccTouchesMoved(CCSet * set,CCEvent * e)
{
CCLOG("hello moved");
}
void HelloWorld::ccTouchesEnded(CCSet * set,CCEvent * e)
{
CCLOG("hello ended");
}
void HelloWorld::onEnter()
{
CCLayer::onEnter();
}
void HelloWorld::onExit()
{
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
}