Hi guys, I’m starting using cocos2d-x right now (and starting c++ as well), so, I created a Class and I add the CCLayer characteristics on that MyClass : CCLayer, but the problem is, when I try to use the touch events as ccTouchesEvent(CCSet* touches,CCEvent* event), the touches~~>begin; or touches~~>anyObject(); just don’t answer and I set
this->setTouchEnabled(true); before that, do you have any clue guys? really thank you for any help
Just for fun, can you provide a bit of sample code? Trying to parse your statement right now in the night made my head hurt
Monocle Society wrote:
Just for fun, can you provide a bit of sample code? Trying to parse your statement right now in the night made my head hurt :
P>setTouchEnabled(true);
Here:
bool Menu::init
{
if ) )
{
return false;
}
this
playBtn = CCMenuItemImage::create(“CloseNormal.png”, “CloseSelected.png”);
MenuBox = CCMenu::create();
MenuBox~~>addChild;
MenuBox~~>setPosition(0, 0);
this~~>addChild;
playBtn~~>setPosition(100, CCDirector::sharedDirector()>getWinSize.height/2);>schedule(schedule_selector(Menu::update));
this
this~~>schedule);
//this method is not working at all
return true;
}
SceneClass::Scenes Menu::update
{
return SceneClass::MainMenu;
}
void Menu::ccTouchesEnded
{
CCSetIterator it = pTouch~~>begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint tPosition = touch->getLocation();
tPosition = CCDirector::sharedDirector()->convertToGL( tPosition );
}
-
For multi-touch to work, you need to enable it first on iOS (Android automatically enables it). Open up AppController.mm and right below the creation of the EGLView object, add the line **[ **glView setMultipleTouchEnabled: YES ];*
-
On your CCLayer inherited class, you don’t schedule the ccTouchesEvent protocols. Youoverride them. Declare them as**virtual* in your header file. Also, you might want to se CCLayer as public. Something like this:
class Menu : public cocos2d::CCLayer {
public:
static cocos2d::CCScene * scene();
virtual bool init();
CREATE_FUNC( Menu );// Touch Handlers virtual void ccTouchesBegan( CCSet * touches, CCEvent * event ); // When touches are started. virtual void ccTouchesMoved( CCSet * touches, CCEvent * event ); // When touches are moved virtual void ccTouchesEnded( CCSet * touches, CCEvent * event ); // When touches are ended.
};
-
You need to register the layer to the CCTouchDispatcher, not schedule the touches,
bool Menu::init() {
if ( !CCLayer::init() ) return false;// Do stuff here // Register the layer to touch dispatcher CCDirector::sharedDirector() -> getTouchDispatcher() -> addStandardDelegate( this, 0 );
}
After that it should work now, provided that you define the touch handlers on the header file. This should work on cocos2d-x 2.0.4 on both iOS and Android.
thank you, it really worked :D, I still learning how to use a Scene Manager :D, but thank you anyways, it was really helpful : )