cocos2dx 3d開源項目 fantasyWarrior3D 從零走起[LoadingScene & MainMenuScene],cocos2dx開源遊戲

來源:互聯網
上載者:User

cocos2dx 3d開源項目 fantasyWarrior3D 從零走起[LoadingScene & MainMenuScene],cocos2dx開源遊戲


[AppDelegate.cpp] 
還是從applicationDidFinishLaunching()開始好了
發現這裡多了一個對指令碼進行加密的方法
(1) stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA"));  
(2)通過config.json配置來找到lua的入口main.lua並執行,再跳轉到第一個介面LoadingScene

engine->executeScriptFile(ConfigParser::getInstance()->getEntryFile().c_str());


[LoadingScene]
1. LoadingScene的構造順序:(1) LoadingScene:create() 被外部調用
(2)在create中首先執行LoadingScene:new() ,如下定義才會生效
把自己初始化為一個 scene:
local MainMenuScene = class("MainMenuScene",function()
    return cc.Scene:create()
end
)

(3)ctor()
由於使用了 cocos2dx-lua function.lua 定義的class方法,所以會預設調用子類的建構函式 ctor()
(4)在create最後調用 LoadingScene:init()  完成其他子物件的初始化

2. init() 中啟用了一個調度器來執行update以更新子物件的狀態cc.Director:getInstance():getScheduler():scheduleScriptFunc(update,0.1,false)
update 做了哪些事:
(1)每0.1秒 緩衝一個粒子和素材
LoadingScene:cachedParticleRes()
LoadingScene:cachedTextureRes()


(2)調整進度條的位置 loadingbar:setPercent((self._totalResource-self._num)/self._totalResource*100)


(3) 如果發現已經載入完畢了就跳轉
local scene = require("MainMenuScene")
cc.Director:getInstance():replaceScene(scene:create())

[MainMenuScene]
//靜態函數,用於設定預設帶ALPHA通道的貼映像素格式。則圖片建立為貼圖時,如果有ALPHA通道,則產生此預設貼映像素格式。  
static void setDefaultAlphaPixelFormat(CCTexture2DPixelFormat format);  
1. addCloud 添加雲朵(1) 開啟一個移動雲朵的調度器,頻率是每秒60次
self.scheduleCloudMove = cc.Director:getInstance():getScheduler():scheduleScriptFunc(cloud_move,1/60,false)
2. addlogo  來回搖擺的實現    local function logoShake()
        --rand_n = range * math.sin(math.rad(time*speed+offset))
        local rand_x = 0.1*math.sin(math.rad(time*0.5+4356))
        local rand_y = 0.1*math.sin(math.rad(time*0.37+5436)) 
        local rand_z = 0.1*math.sin(math.rad(time*0.2+54325))
        logo:setRotation3D({x=math.deg(rand_x),y=math.deg(rand_y),z=math.deg(rand_z)})
        time = time+1
    end
    self.logoSchedule = cc.Director:getInstance():getScheduler():scheduleScriptFunc(logoShake,0,false)

其實這段代碼可以看作是
        local rand_x = 0.1*math.sin(math.rad(time))
        local rand_y = 0.1*math.sin(math.rad(time)) 
        local rand_z = 0.1*math.sin(math.rad(time))
通過math.rad 把time限制為360以內得一個弧度,再通過 math.sin 轉換為一個區間數值[-x,x],
最後 *0.1 將擺動幅度降低,這樣就實現了一個 x,y,z軸上的來回搖擺

這個裡在cocosIDE裡面設定數值發現邊框特效突然沒了,“即視”功能還是有點bug呀

3. addPointLight  長翅膀的那個傢伙(1) getLightSprite()來構造身體用到了alpha混色,以達到羽翼等部分的半透明效果
self._lightSprite:setBlendFunc(gl.ONE,gl.ONE_MINUS_SRC_ALPHA)
GL_ONE:1.0
GL_ONE_MINUS_SRC_ALPHA:1.0減去源的Alpha值作為因子

參考 http://cn.cocos2d-x.org/tutorial/show?id=1739

(2)法線貼圖 以實現凹凸效果

local effectNormalMapped = cc.EffectNormalMapped:create("mainmenuscene/logo_normal.png");
effectNormalMapped:setPointLight(self._pointLight)
effectNormalMapped:setKBump(50)   這個是設定凹凸值?

(3) “圓周運動” 與 拖拽
onTouchBegin 記錄當前位置,並且開啟移動處理函數 movePoint
onTouchEnded 關掉移動處理函數,並且調用 getBezierAction() 重新開始“圓周運動”

movePoint :
值得注意的是 使用lerp 函數來擷取插值,達到一個減速和加速的移動效果。
movePoint函數: local point = cc.pLerp(lightSpritePos,self._prePosition,dt*2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.