All areas of my game is a scene:
Splash
Menu
StageSelect
Stage
But on stage, i need get touch events, but when i search i only find for CCLayer.
CCScene doesnt support touch events?
All areas of my game is a scene:
Splash
Menu
StageSelect
Stage
But on stage, i need get touch events, but when i search i only find for CCLayer.
CCScene doesnt support touch events?
I solve the problem. Thanks
I will post the solution to help others:
1 - On my StageScene (CCScene) i implement CCTouchDelegate
class StageScene : public cocos2d::CCScene, public CCTouchDelegate
2 - I need create some methods to receive touch events (StageScene.h):
registerWithTouchDispatcher
ccTouchEnded
ccTouchCancelled
ccTouchBegan
you can see the implementation in other samples
3 - O init method of scene you call “registerWithTouchDispatcher” to register it.
Now you will receive the events.
I dont know the difference of layer/scene in the game
We dont need scene so?
To enable touches in a class derived from Scene, you need to do following:
Inherit from CCStandardTouchDelegate
class DerivedScene : public cocos2d::CCScene, public cocos2d::CCStandardTouchDelegate
Add the following to DerivedScene’s init()
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate((CCTouchDelegate*)this, 0);
Declare & Define a destructor for DerivedScene as (here we undo what we did in init above):
DerivedScene::~DerivedScene()
{
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate((CCTouchDelegate*)this);
}
Declare & Define ccTouchesBegan and other touch handling methods that you need
void ccTouchesBegan(cocos2d::CCSet* pTouches, cocos2d::CCEvent* pEvent);
void ccTouchesEnded(cocos2d::CCSet* pTouches, cocos2d::CCEvent* pEvent);
BINGO!