cocos-2dx 随记- 打飞机(main.lua) - 第4天

嗯...好多事都没有坚持下来,本篇文章是我自娱自乐,会随时更新,每天写一点就上传一点。

require "src.cocos.init"


--设置分辨率大小
local designResolutionSize = cc.size(320,568)


--三种资源大小
local smallResolutionSize = cc.size(640,1136)
local largeResolutionSize = cc.size(750,1334)


--cclog 声明cclog日志函数
cclog = function(...)
print(string.format(...))
end


local function main()
--垃圾回收
collectgarbage("collect")
collectgarbage("setpause",100)
collectgarbage("setstepmul",5000)


-- cc.FileUtils:getInstance():addSearchPath("src")
-- cc.FileUtils:getInstance():addSearchPath("res")


local director = cc.Director:getInstance()
    local glview = director:getOpenGLView()


    --系统目录
    local shareFileUtils = cc.FileUtils:getInstance()
    shareFileUtils:addSearchPath("src")
    shareFileUtils:addSearchPath("res")


    local searchPaths = shareFileUtils:getSearchPaths()
    local resPrefix = "res/"
    
    --屏幕大小
    local frameSize = glview:getFrameSize()


    --如果屏幕分辨率看大于samll尺寸得资源分辨率高度,选择large资源
    if frameSize.height > smallResolutionSize.height then
        director:setContentScaleFactor(math.min(largeResolutionSize.height/designResolutionSize.height,largeResolutionSize.width/designResolutionSize.width))
        table.insert(searchPaths,1,resPrefix.."large")
    else
        director:setContentScaleFactor(math.min(smallResolutionSize.height/designResolutionSize.height,smallResolutionSize.width/designResolutionSize.width))
        table.insert(searchPaths,1,resPrefix.."small")
    end


    --设置资源搜索路径
    shareFileUtils:setSearchPaths(searchPaths)


    --设置设计分辨率策略
    glview:setDesignResolutionSize(designResolutionSize.width,designResolutionSize.height,cc.ResolutionPolicy.FIXED_WIDTH)
    
    --设置是否显示帧率和精灵个数
    director:setAnimationStats(true)


    --设置帧率
    director:setAnimationInterval(1.0/60)


    --创建场景
    local scene = require("LoadingScene")
    local loadingScene = scene:create()


    if director:getRunningScene() then
        director:replaceScene(loadingScene)
    else
        director:runWithScene(loadingScene)
    end


end

你可能感兴趣的:(lua篇-打飞机)