cocos2d-x的CCLayer触摸事件

cocos2d-x版本:2.1.3

编译环境:vs2010(xp)


假如HelloWorldLayer继承了CCLayer类,我要在HelloWorldLayer图层里写多点触摸事件。
1.首先要重写下列三个函数
	virtual void ccTouchesBegan(CCSet *touches,CCEvent *pEvent);
	virtual void ccTouchesMoved(CCSet *touches,CCEvent *pEvent);
	virtual void ccTouchesEnded(CCSet *touches,CCEvent *pEvent);
	virtual void ccTouchesCancelled(CCSet *touches,CCEvent *pEvent);

2.然后在init函数里添加
	setTouchEnabled(true);

3.然后实现上述三个函数
void HelloWorld::ccTouchesBegan( CCSet *touches,CCEvent *pEvent )
{
	CCLOG("Began");
}
void HelloWorld::ccTouchesMoved( CCSet *touches,CCEvent *pEvent )
{
	CCLOG("Moved");
}
void HelloWorld::ccTouchesEnded( CCSet *touches,CCEvent *pEvent )
{
	CCLOG("Ended");
}
void HelloWorld::ccTouchesCancelled(CCSet *touches,CCEvent *pEvent)
{
	CCLOG("Cancelled");
}

你可能感兴趣的:(cocos2d-x)