cocos2dx ios入口类_2.cocos2d-x 第一个项目
大家看到了cocos2d-x引擎提供的5種可選擇的模板。
cocos2dx:標準模板(無物理類庫,無腳本類庫)
cocos2dx_box2d(box2d物理游戲模板)
cocos2dx_chipmunk(chipmunk物理游戲模板)
cocos2dx_js(含js腳本類庫)
cocos2dx_lua(含lua腳本類庫)
我們選擇cocos2dx標準模板即可。
如下圖輸入product name和company identifier
點擊NEXT,選好目錄地址后即可完成創建,新項目如下圖。
首先我們來看一下cocos2dx的項目結構。
大家看上圖的左邊,主要有以下幾個目錄:
Resources: 資源存放目錄
ios:項目運行的入住口(main函數 :))
libs:cocos2dx引擎的庫以及其他擴展的一些類庫
classes:cocos2dx引擎入口
support files:其他文件
framework:ios 的sdk
products:產品存放的目錄
我們常用的入口就是classes目錄了,下面我們來看下AppDelegate.cpp的代碼,
我在重要的地方都加了注釋
在看代碼之前,我稍微介紹幾個類的概念。
CCDirector:顧名思義,導演就是控制不同場景之間的切換
CCScene:一個游戲由游戲場景,暫停菜單場景,主菜單場景等多個場景組成。
CCLayer:每個場景中由多個層來組成,比如游戲中有遠景地圖,精靈層,前景裝飾,HUD界面等層組成。
CCSprite:如雷電游戲由一個飛機精靈,多個敵人精靈等較色,并且有不同的狀態。
//
// Hello_worldAppDelegate.cpp
// Hello_world
//
// Created by wenbin.cai on 13-5-30.
// Copyright __MyCompanyName__ 2013年. All rights reserved.
//
#include "AppDelegate.h"
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
#include "HelloWorldScene.h"
USING_NS_CC;
using namespace CocosDenshion;
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
}
bool AppDelegate::applicationDidFinishLaunching() //三個生命周期函數之一:游戲啟動時執行
{
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector(); //獲得唯一的一個導演對象
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS
pDirector->setDisplayStats(true); //設置顯示狀態,看運行圖中的左下角(對象數,time per second,FPS幀數)
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);//設置游戲幀數FPS
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();//創建一個場景
// run
pDirector->runWithScene(pScene);//導演展現一個場景
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()//三個生命周期函數之二:程序被切換至后臺時執行
{
CCDirector::sharedDirector()->stopAnimation(); //整個游戲停止動畫
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); //停止播放背景音樂
SimpleAudioEngine::sharedEngine()->pauseAllEffects();//展廳所有特效
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()//三個生命周期函數之三,程序從后臺切回到前臺時執行。
{
CCDirector::sharedDirector()->startAnimation();//開始所有動畫
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); //繼續播放背景音樂
SimpleAudioEngine::sharedEngine()->resumeAllEffects();//繼續所有特效
}
看完代碼,讓我們運行下我們的第一個cocos2dx項目把~注意左下角3個數字
大概了解了項目的結構,我們可以正式開始學習cocos2dx了~
大家一起加油~~
大小: 234.4 KB
大小: 65 KB
大小: 78.4 KB
大小: 55.4 KB
分享到:
2013-05-30 22:44
瀏覽 1797
評論
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的cocos2dx ios入口类_2.cocos2d-x 第一个项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux中怎么如何使用userdel命
- 下一篇: datax 模板_dataX3.0安装使