-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.lua
More file actions
70 lines (57 loc) · 2.74 KB
/
Copy pathMain.lua
File metadata and controls
70 lines (57 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--main()函数
require "cocos.init"
--设计分辨率大小
local designResolutionSize = cc.size(320, 568)--设计大小
local smallResolutionSize = cc.size(640, 1136)
local largeResolutionSize = cc.size(750, 1334)
cclog = function(...)
print(string.format(...))
end
local function main()
collectgarbage("collect")
-- avoid memory leak(避免内存泄漏)
collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000)
--获得当前平台
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
(cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform)--判断io设备
--添加路径
local sharedFileUtils = cc.FileUtils:getInstance()
sharedFileUtils:addSearchPath("src")
sharedFileUtils:addSearchPath("res")
--获取所有路径
local searchPaths = sharedFileUtils:getSearchPaths()
--获取屏幕大小frameSize
local director = cc.Director:getInstance()
local glview = director:getOpenGLView()
local frameSize = glview:getFrameSize()--FrameSize是画框,WinSize是画布
-- 如果屏幕分辨率高度大于small尺寸的资源分辨率高度,选择large资源。
if frameSize.height > smallResolutionSize.height then
director:setContentScaleFactor(math.min(largeResolutionSize.height / designResolutionSize.height, largeResolutionSize.width / designResolutionSize.width))
table.insert(searchPaths, 1, "res/large")
--如果屏幕分辨率高度小等于small尺寸的资源分辨率高度,选择small资源。
else
director:setContentScaleFactor(math.min(smallResolutionSize.height / designResolutionSize.height, smallResolutionSize.width / designResolutionSize.width))
table.insert(searchPaths, 1, "res/small")
end
--设置资源搜索路径
sharedFileUtils:setSearchPaths(searchPaths)
-- 设置设计分辨率策略
glview:setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, cc.ResolutionPolicy.FIXED_WIDTH)
--设置是否显示帧率和精灵个数
director:setDisplayStats(true)
--设置帧率
director:setAnimationInterval(1.0 / 60)
--create scene
local scene = require("LoadingScene")
local gameScene = scene.create()
if cc.Director:getInstance():getRunningScene() then
cc.Director:getInstance():replaceScene(gameScene)
else
cc.Director:getInstance():runWithScene(gameScene)
end
end
local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
error(msg)
end