Updating a project from Cocos2d-x 2.2x to 3.x

Some quick notes on things you need to do when updating a Cocos2dx project from 2.2.x to 3.x.  These are things you need to do just to get your project to compile, not to get rid of any depreciated calls.


If you create menus likes this:

 CCMenuItem * QuitButton= CCMenuItemImage::create("quit.png"

     menu_selector(DownHill::Quit) );

You need to change the menu Selector from

 void Quit();


 void Quit(Object* sender);

Scheduled calls

If you used scheduled calls like this:

this->scheduleOnce( schedule_selector(GameBase::RestartRound),2.5f);

you need to make sure 'RestartRound' takes a float, like this:

 void RestartRound(float f);

Particle System

I used to create a particle system like this, but now this is protected

    CCParticleSystem*  particle =  new  CCParticleSystemQuad ();

    particle-> initWithTotalParticles (100);

so instead it's this:

    ParticleSystem*  particle =  ParticleSystemQuad::create ();


Touch Events

Big changes to the way touch events work (for the better!) but to just get things going in the old way, change ccTouchBegan to onTouchBegan (same for Moved and Ended) and then register to get the events like this:

    // Register Touch Event
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(DownHill::onTouchBegan, this);
    listener->onTouchMoved = CC_CALLBACK_2(DownHill::onTouchMoved, this);
    listener->onTouchEnded = CC_CALLBACK_2(DownHill::onTouchEnded, this);
    dispatcher->addEventListenerWithSceneGraphPriority(listener, this);

I'll add more as I find them!

Also, this post is really helpful:

No comments:

Post a Comment