Cocos2d-x v3.2 FlappyBird Class Object code analysis (1)
I haven't written a blog for a long time. When I got up this morning, I opened csdn and sent my resume to several companies, all of which were in the dark and I was idle at school, I plan to analyze some code in the previously written Flappy Bird.
Flappy Bird also has a lot of tutorials on the Internet. Some of my code is also referred to on the Internet. It cannot be completely original, but a large part of the code is based on my own ideas, designed to write out, contact cocos2d-x has been almost a year, from 2x to now 3x, changed a lot of things, as a newbie I still have a lot of things to learn.
Note the following before you start:
1) My Flappy Bird Resources are used differently from those on the Internet. For details, refer to my previous blog.
2) part of the code reference http://blog.csdn.net/column/details/flappybird.html respect the original author
3) I am also a newbie. Some code may be poorly written and not rigorous. Please forgive me)
4) many codes are analyzed in comments and may be written outside.
The first article first introduces some of the less important classes and header files in this game:
This header file mainly defines some frequently used constants for testing and modification.
// Define. h # pragma once # define bird "BIRDANIMATION_0" // yellow bird animation # define BIRDANIMATION_1 "birdAnimation_1" // Blue Bird animation # define BIRDANIMATION_2 "birdAnimation_2" // red bird animation # define bird animation # // bird wings frequency # define LOADING_NUM2 // loading animation frequency # define LOADING_FRE0.5f // loading animation frequency # define BIRD_RADIUS15 // bird radius # define GRAVITYPoint (0, -980) // gravity acceleration # define VELOCITYPoint (0,260) // The bird clicks the upward velocity # define THROUGH_HEIGHT120 // The height of the bird passing through two tubes # define PIPE_UP1001 // The tag of the upward pipe # define PIPE_DOWN1002 // The tag of the downward pipe # define PIPE_RANGE200 // tube movement Y value range # define PIPE_X300 // tube start to move X value # define PIPE_Y-170 // tube start to move Y value # define PIPE_TIME3.0f // tube Movement time # define PIPE_VELOCITYPoint (-360,0) // The distance and direction of the tube movement # define LAND_VELOCITY1/60 // The moving speed of the lawn # define PIPE_FRE1.5f // the frequency of the tube # define BIRD_DIE_ROTATION90 // The angle of the bird's death # define animation time # define ADDSCORE_FRE0.05f // Add frequency # define CHANGESCENE_TIME0.5f // scenario switching time # define MEDALS_05 // trophy 1 score # define MEDALS_110 // trophy 2 score # define MEDALS_110 MEDALS_215 // trophy 3 score # define MEDALS_320 // trophy 4 score
Below this class does not analyze, understand cocos2d-x all understand
// AppDelegate. h # include "AppDelegate. h" # include "HelloWorldScene. h" # include "WelcomeScene. h" break; AppDelegate: AppDelegate () {} AppDelegate ::~ AppDelegate () {} bool AppDelegate: applicationDidFinishLaunching () {// initialize director auto director = Director: getInstance (); auto glview = director-> getOpenGLView (); if (! Glview) {// cocos2d-x 3.2 this class has also changed a lot, the following statement defines the window name, size, and zoom ratio glview = GLView: createWithRect ("FlappyBird ", rect (286,512,), 1.0f); director-> setOpenGLView (glview);} // This is a simple resolution adaptation ..... other codes are built-in with 3.2. Here we will not explain glview-> setDesignResolutionSize (268,512, ResolutionPolicy: EXACT_FIT); // turn on display FPS director-> setDisplayStats (true ); // set FPS. the default value is 1.0/60 if you don't call this ctor-> setAnimationInterval (1.0/60); // create a scene. it's an autorelease object // auto scene = HelloWorld: createScene (); auto scene = WelcomeScene: createScene (); // run director-> runWithScene (scene ); return true;} // This function will be called when the app is inactive. when comes a phone call, it's be invoked toovoid AppDelegate: applicationDidEnterBackground () {Director: getInstance ()-> stopAnimation (); // if you use SimpleAudioEngine, it must be pause // SimpleAudioEngine: getInstance ()-> pauseBackgroundMusic ();} // this function will be called when the app is active againvoid AppDelegate: applicationWillEnterForeground () {ctor: getInstance ()-> startAnimation (); // if you use SimpleAudioEngine, it must resume here // SimpleAudioEngine: getInstance ()-> resumeBackgroundMusic ();}
Well, today we will simply put these two files. I am not sure when the next article will be updated ........