I am a big rookie, just entry cocos2d-x soon, decided to write a little game practice feel, found OiteBoys Article cocos2dx production flappybird, and then learn, used to practice
The author's version is version 3.0 beta, but there is a slight difference in version 3.0 rc0:
1) The onContactBegin parameter of the physical collision is changed to one
// Auto contactListener = EventListenerPhysicsContact: create (); contactListener-> onContactBegin = CC_CALLBACK_1 (GameLayer: onContactBegin, this); this-> getEventDispatcher () -> addEventListenerWithSceneGraphPriority (contactListener, this );
Listener Function
bool GameLayer::onContactBegin(PhysicsContact& contact) {this->gameOver();return true;}
2. body Parameters
Add the following attributes when adding the body to the bird and pipe. Otherwise, the onContactBegin function is not triggered.
body->setCategoryBitmask(1); // 0001body->setContactTestBitmask(-1); // 0100body->setCollisionBitmask(-1); // 0011
Then there is a tiny bug in the author's code, that is, after clicking retartBtn, the bird will disappear immediately after the collision, rather than disappear after the landing. The solution is to set the bird to the singleton mode.
Use normal CREATE_FUNC ().
Appendix:
Flappybird source code