Cocos2d-x v3.2 flappybird Specific code analysis for each class object (1)

Source: Internet
Author: User

Haven't written a blog for a long time, this morning do not know how to open the CSDN, work resume has also voted several, all go down, in the school also idle nothing, is going to write the previous Flappy Bird inside some code analysis sent out.

Flappy Bird Online also has a lot of tutorials, some of my code is also reference online, not completely original it, but also a large part of the code is in accordance with my own ideas, design written out, contact Cocos2d-x has almost a year, from the previous 2x to now 3x, Changed a lot of things, as a novice I have a lot of things to learn.

There are a few things to note before you start:

1) My Flappy Bird the use of resources and online is not the same, specific reference to my previous blog.

2) Part of the Code reference http://blog.csdn.net/column/details/flappybird.html respecting the original author

3) I also rookie, may part of the code is not good, not rigorous, please forgive us (everyone one another it)

4) A lot of code analysis is in the comments, it may also be written outside.

The first article introduces some of the less important classes and header files in this game:

This header file mainly defines some constants that are often used to facilitate testing and modification.

Define.h#pragma once#define birdanimation_0 "birdanimation_0"//Yellow Bird Animation # # birdanimation_1 "birdanimation_1"// Blue Bird Animation # # birdanimation_2 "birdanimation_2"//Red Bird Animation # # bird_fly_fre0.1f//Bird Wing frequency # define loading_num2// Loading number of animations # define loading_fre0.5f//loading Animation frequency # define bird_radius15//Bird Radius # define GRAVITYPOINT (0,-980)//Gravitational acceleration # Define Velocitypoint (0,260)//Bird Click up to fly Speed # define through_height120//bird through two pipe height # # pipe_up1001//up Pipe Tag#define pipe_down1002//down pipe tag#define pipe_range200//pipe moves the range of Y values # define pipe_x300//the beginning of the movement of the X-value # define pipe_y-170// The minimum y value of the pipe start movement # define pipe_time3.0f//Tube Motion Time # # Pipe_velocitypoint ( -360,0)//pipe motion distance and direction # define Land_velocity1/60/ /Grassland Movement Speed # define pipe_fre1.5f//tube appears frequency # define bird_die_rotation90//bird death after the angle # define scorecard_show_time0.6f// Scoreboard appears animation time # define addscore_fre0.05f//Plus frequency # define changescene_time0.5f//scene switch time # define medals_05//Trophy 1 score # define Medals _110//Trophy 2 score # define medals_215//Trophy 3 score # define medals_320//Trophy 4 score

The following class is not analyzed, understand cocos2d-x understand

Appdelegate.h#include "AppDelegate.h" #include "HelloWorldScene.h" #include "WelcomeScene.h" USING_NS_CC; 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 also changed a lot, the following statement defines the window's name, size, and scale Glview = Glview::createwithrect ("Flappybird", Rect (0,        0,286,512), 1.0f);    Director->setopenglview (Glview); }//This is a simple resolution adaptation .....    The other code is 3.2, which does not explain the 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 director->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 was called when the app was inactive. When comes a phone Call,it's be invoked toovoid Appdelegate::applicationdidenterbackground () {director::getinstance ()-    >stopanimation (); If you use Simpleaudioengine, it must is pause//simpleaudioengine::getinstance ()->pausebackgroundmusic ();} This function would be called when the app is active againvoid Appdelegate::applicationwillenterforeground () {Direct    Or::getinstance ()->startanimation (); If you use the Simpleaudioengine, it must resume here//Simpleaudioengine::getinstance ()->resumebackgroundmusic ();}

OK, today is a simple two of these files, the next article update is when I am not sure ...

Cocos2d-x v3.2 flappybird Specific code analysis for each class object (1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.