Layer派生类只响应onTouchBegan,不响应onTouchMoved和onTouchEnded,是何道理?

HelloWorldScene.h
class HelloWorld : public cocos2d::Layer
{
public:
// there’s no ‘id’ in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here’s a difference. Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void onTouchEnded(cocos2d::Touch *pTouch, cocos2d::Event pEvent);
cocos2d::Sprite
m_choosedSprite;

cocos2d::Sprite* genSprite(float posX, float posY, const std::string& picName);

// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);

};

HelloWorldScene.cpp相关代码
#include “HelloWorldScene.h”
#include “math//kazmath//kazmath//vec2.h”
USING_NS_CC;
static int InOrderIdx = 0;

Scene* HelloWorld::createScene()
{
// ‘scene’ is an autorelease object
auto scene = Scene::create();

// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);

// return the scene
return scene;
}

bool HelloWorld::onTouchBegan(Touch *pTouch, Event *pEvent)
{
Point pnt = pTouch->getLocation();
CCLog(“x:%f, y:%f\n”, pnt.x, pnt.y);
auto sp1 = genSprite(pnt.x, pnt.y, “test1.png”);
auto r1 = RotateBy::create(3, 360);
auto rotate_forever = RepeatForever::create(Sequence::create(r1, r1, NULL));
sp1->runAction(rotate_forever);
this->m_choosedSprite = sp1;
return cocos2d::Layer::ccTouchBegan(pTouch, pEvent);
}
void HelloWorld::onTouchMoved(Touch *pTouch, Event *pEvent)
{
CCLog("move ");
Point pnt = pTouch->getLocation();
if (m_choosedSprite)
m_choosedSprite->setPosition(pnt);
}
void HelloWorld::onTouchEnded(Touch *pTouch, Event *pEvent)
{
CCLog("end ");
Point pnt = pTouch->getLocation();
if (m_choosedSprite)
m_choosedSprite->setPosition(pnt);
}

// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}

Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();

this->m_choosedSprite = NULL;
/////////////////////////////
// 2. add a menu item with “X” image, which is clicked to quit the program
// you may modify it.
// add a “close” icon to exit the progress. it’s an autorelease object
auto closeItem = MenuItemImage::create(“CloseNormal.png”,
“CloseSelected.png”,
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));

closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it’s an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Point::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below…
// add a label shows “Hello World”
// create and initialize a label

auto label = LabelTTF::create("Chinese is not supported!", "Arial", 36);

// position the label on the center of the screen
label->setPosition(Point(origin.x + visibleSize.width/2,
                        origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
// position the sprite on the center of the screen
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer

// this->addChild(sprite, 0);

auto p1 = Sprite::create(“test1.png”);
auto p2 = Sprite::create(“test2.png”);
auto p3 = Sprite::create(“test3.png”);

this->addChild(p1, ++InOrderIdx);
this->addChild(p2, ++InOrderIdx);
this->addChild(p3, ++InOrderIdx);
const int picWidth = 50;
p1->setPosition(picWidth / 2, picWidth);
p2->setPosition(picWidth / 2, picWidth * 2);
p3->setPosition(picWidth / 2, picWidth * 3);
auto s = Director::getInstance()->getWinSize();
auto rotate = RotateBy::create(2, 360);
auto action = RepeatForever::create(rotate);
auto rotate_back = rotate->reverse();
auto rotate_seq = Sequence::create(rotate, rotate_back, NULL);
auto rotate_forever = RepeatForever::create(rotate_seq);
auto scale = ScaleBy::create(5, 1.5f);
auto scale_back = scale->reverse();
auto scale_seq = Sequence::create(scale, scale_back, NULL);
auto scale_forever = RepeatForever::create(scale_seq);
p1->runAction(rotate_forever);
p2->runAction(scale_forever);
p3->runAction(rotate_forever);
auto moveto = MoveTo::create(1, Point(0,0));
auto old_pos = p2->getPosition();
auto moveto_back = MoveTo::create(1, old_pos);
CCLog(“cur_pos:(%f, f)\n", old_pos.x, old_pos.y); auto moveto_seq = Sequence::create(moveto, moveto_back, NULL); auto move_forever = RepeatForever::create(moveto_seq); p2->runAction(move_forever); //---------------------------------------------------------------------------- // 性能测试程序,生成500个精灵,在屏幕上反复转动 //---------------------------------------------------------------------------- CCSize size = CCDirector::sharedDirector()->getVisibleSize(); int scrWidth = size.width, scrHeight = size.height; Point pnt(0, 0); for (int idx = 0; idx < 500; ++idx) { pnt.x = (rand() scrWidth + scrWidth /2) / 2;
pnt.y = (rand() % scrHeight + scrHeight /2) / 2;
CCLog(”(x, y):%f, %f\n", pnt.x, pnt.y);
auto sp1 = genSprite(pnt.x, pnt.y, “test2.png”);
auto r = RotateBy::create(50, 36010);
auto rot_seq = Sequence::create(r, r, NULL);
auto rot_forever = RepeatForever::create(rot_seq);
sp1->runAction(rot_forever);
}
/

auto sp1 = genSprite(0, 0);
auto r = RotateBy::create(30, 360 * 10);
sp1->runAction®;
*/

//----------------------------------------------------------------------------
// 指针事件回调响应
//----------------------------------------------------------------------------
/*
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);

Rect rect = Rect(0, 0, scrWidth, scrHeight);
listener->onTouchBegan = (Touch* pTouch, Event* pEvent){
Point pnt = pTouch->getLocation();
CCLog(“Began!-------- x:%f, y:%f\n”, pnt.x, pnt.y);
auto sp1 = genSprite(pnt.x, pnt.y, “test1.png”);
auto r1 = RotateBy::create(3, 360);
auto rotate_forever = RepeatForever::create(Sequence::create(r1, r1, NULL));
sp1->runAction(rotate_forever);
this->m_choosedSprite = sp1;
return cocos2d::Layer::ccTouchBegan(pTouch, pEvent);
};
listener->onTouchEnded = (Touch* pTouch, Event* pEvent){
Point pnt = pTouch->getLocation();
CCLog(“Ended!-------- x:%f, y:%f\n”, pnt.x, pnt.y);
};
listener->onTouchMoved = (Touch* pTouch, Event* pEvent){
Point pnt = pTouch->getLocation();
CCLog(“Moveing!------ x:%f, y:%f\n”, pnt.x, pnt.y);
};
*/
//----------------------------------------------------------------------------
// 指针事件回调响应
//----------------------------------------------------------------------------
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}

bool HelloWorld::onTouchBegan(Touch *pTouch, Event *pEvent)
里 return true;