Cocos2d-x 3.0 game instance learning notes "parkour" first Interface

Source: Internet
Author: User

Cocos2d-x3.0 mobile game development C ++ instance Parkour

The starting interface is similar to that of its predecessors:Cocos2d-x game development (a) Start InterfaceBut there are also differences

The following describes all the resources used in the game.

The START interface is defined as mainscene with the following functions:

1. Background

2. Enter the game interface button

3. Pre-load the background music file

. H file

#ifndef __MainScene__H__#define __MainScene__H__#include "cocos2d.h"class MainScene : cocos2d::Layer{public:virtual bool init();static cocos2d::Scene* scene();CREATE_FUNC(MainScene);private://void createBG();//void createButton(cocos2d::Point centerPoint);//void preLoadMusic();//menu start the gamevoid start();};/**/#endif
. Cpp
#include "MainScene.h"#include "SimpleAudioEngine.h"//#include "PlayScene.h"USING_NS_CC;using namespace CocosDenshion;Scene* MainScene::scene(){Scene* scene = Scene::create();Layer* layer = MainScene::create();scene->addChild(layer);return scene;}bool MainScene::init(){if(!Layer::init()){return false;}//preloadMusicpreLoadMusic();//create backgroundcreateBG();return true;}void MainScene::createBG(){auto winSize = Director::getInstance()->getWinSize();auto centerPoint = ccp(winSize.width / 2, winSize.height / 2);//BGSprite* spriteBg = Sprite::create("MainBG.png");spriteBg->setPosition(centerPoint);this->addChild(spriteBg);//create buttoncreateButton(centerPoint);}void MainScene::createButton(cocos2d::Point centerPoint){//Start muttonMenuItemImage* menuItem = MenuItemImage::create("start_n.png","start_s.png",CC_CALLBACK_0(MainScene::start,this));Menu* menu = Menu::create(menuItem,NULL);menu->setPosition(centerPoint);this->addChild(menu);}void MainScene::preLoadMusic(){SimpleAudioEngine* audioEngin = SimpleAudioEngine::getInstance();audioEngin->preloadBackgroundMusic("background.mp3");audioEngin->preloadEffect("jump.mp3");audioEngin->preloadEffect("crouch.mp3");}void MainScene::start(){CCLOG("game is start !");//Scene* playScene = TransitionFade::create(1,PlayScene::createScene());//Director::getInstance()->replaceScene(playScene);}
I am not familiar with screen self-adaptation. Although I have read several articles, I am still confused and do not know how to use them in the instance. So in this rewriting, generally, the background image is 640*320 in size, so it must be in appdelegate. in CPP, set the display window size:

Bool appdelegate: applicationdidfinishlaunching () {// initialize Director auto Director = Director: getinstance (); Auto glview = Director-> getopenglview (); If (! Glview) {glview = glview: Create ("My Game"); glview-> setframesize (640,320); // ------ modify the display window size Director-> setopenglview (glview );} // 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 objectauto scene = mainscene: Scene (); // run Director-> runwithscene (scene); Return true ;}
I can only learn more about it later. If you have a good tutorial, please recommend it. Thank you !!

After running

Game resources:Game Resources

Personal ignorance. Thank you for your correction and discussion.

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: 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.