Remove glView setting form cpp to lua script

This commit is contained in:
samuele3hu 2014-07-11 15:34:56 +08:00
parent 54970c109f
commit 82070e5205
6 changed files with 49 additions and 68 deletions

View File

@ -22,24 +22,6 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("Lua Empty Test");
director->setOpenGLView(glview);
}
director->setOpenGLView(glview);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);
// register lua engine // register lua engine
LuaEngine* engine = LuaEngine::getInstance(); LuaEngine* engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine); ScriptEngineManager::getInstance()->setScriptEngine(engine);

View File

@ -14,11 +14,32 @@ function __G__TRACKBACK__(msg)
cclog("----------------------------------------") cclog("----------------------------------------")
end end
local function initGLView()
local director = cc.Director:getInstance()
local glView = director:getOpenGLView()
if nil == glView then
glView = cc.GLView:create("Lua Empty Test")
director:setOpenGLView(glView)
end
director:setOpenGLView(glView)
glView:setDesignResolutionSize(480, 320, cc.ResolutionPolicy.NO_BORDER)
--turn on display FPS
director:setDisplayStats(true)
--set FPS. the default value is 1.0/60 if you don't call this
director:setAnimationInterval(1.0 / 60)
end
local function main() local function main()
-- avoid memory leak -- avoid memory leak
collectgarbage("setpause", 100) collectgarbage("setpause", 100)
collectgarbage("setstepmul", 5000) collectgarbage("setstepmul", 5000)
initGLView()
--support debug,when used on ios7.1 64bit,these codes should be commented --support debug,when used on ios7.1 64bit,these codes should be commented
local targetPlatform = cc.Application:getInstance():getTargetPlatform() local targetPlatform = cc.Application:getInstance():getTargetPlatform()
if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) or if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) or
@ -58,7 +79,7 @@ local function main()
]]-- ]]--
local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5) local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5)
local animate = cc.Animate:create(animation); local animate = cc.Animate:create(animation)
spriteDog:runAction(cc.RepeatForever:create(animate)) spriteDog:runAction(cc.RepeatForever:create(animate))
-- moving dog at every frame -- moving dog at every frame
@ -101,7 +122,7 @@ local function main()
local frameCrop = cc.SpriteFrame:create("res/crop.png", cc.rect(0, 0, 105, 95)) local frameCrop = cc.SpriteFrame:create("res/crop.png", cc.rect(0, 0, 105, 95))
for i = 0, 3 do for i = 0, 3 do
for j = 0, 1 do for j = 0, 1 do
local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop); local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop)
spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2) spriteCrop:setPosition(10 + 200 + j * 180 - i % 2 * 90, 30 + 10 + i * 95 / 2)
layerFarm:addChild(spriteCrop) layerFarm:addChild(spriteCrop)
end end

View File

@ -24,16 +24,6 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("Lua Game Controller Test");
director->setOpenGLView(glview);
}
director->setOpenGLView(glview);
LuaEngine* engine = LuaEngine::getInstance(); LuaEngine* engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine); ScriptEngineManager::getInstance()->setScriptEngine(engine);
LuaStack* stack = engine->getLuaStack(); LuaStack* stack = engine->getLuaStack();

View File

@ -16,10 +16,18 @@ local largeResource =
directory = "ipadhd", directory = "ipadhd",
} }
local glView = cc.Director:getInstance():getOpenGLView() local director = cc.Director:getInstance()
local glView = director:getOpenGLView()
if nil == glView then
glView = cc.GLView:create("Game Controller Test")
director:setOpenGLView(glView)
end
director:setOpenGLView(glView)
local designResolutionSize = cc.size(1920, 1080) local designResolutionSize = cc.size(1920, 1080)
glView:setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, 2) glView:setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, cc.ResolutionPolicy.SHOW_ALL)
local frameSize = glView:getFrameSize() local frameSize = glView:getFrameSize()

View File

@ -19,31 +19,6 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::createWithRect("Lua Tests", Rect(0,0,900,640));
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
director->setAnimationInterval(1.0 / 60);
auto screenSize = glview->getFrameSize();
auto designSize = Size(480, 320);
if (screenSize.height > 320)
{
auto resourceSize = Size(960, 640);
director->setContentScaleFactor(resourceSize.height/designSize.height);
}
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
// register lua engine // register lua engine
LuaEngine* pEngine = LuaEngine::getInstance(); LuaEngine* pEngine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(pEngine); ScriptEngineManager::getInstance()->setScriptEngine(pEngine);

View File

@ -6,25 +6,30 @@ collectgarbage("setstepmul", 5000)
---------------- ----------------
-- run -- run
local director = cc.Director:getInstance()
local glView = director:getOpenGLView()
if nil == glView then
glView = cc.GLView:createWithRect("Lua Tests", cc.Rect(0,0,900,640))
end
local glView = cc.Director:getInstance():getOpenGLView() --turn on display FPS
director:setDisplayStats(true)
--set FPS. the default value is 1.0/60 if you don't call this
director:setAnimationInterval(1.0 / 60)
local screenSize = glView:getFrameSize() local screenSize = glView:getFrameSize()
local designSize = {width = 480, height = 320} local designSize = {width = 480, height = 320}
local fileUtils = cc.FileUtils:getInstance()
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
local dd = glView:getDesignResolutionSize()
if screenSize.height > 320 then if screenSize.height > 320 then
local resourceSize = {width = 960, height = 640} local resourceSize = {width = 960, height = 640}
local rate = resourceSize.height/screenSize.height cc.Director:getInstance():setContentScaleFactor(resourceSize.height/designSize.height)
cc.Director:getInstance():setContentScaleFactor(resourceSize.height/designSize.height);
end end
glView:setDesignResolutionSize(designSize.width, designSize.height, 3);
glView:setDesignResolutionSize(designSize.width, designSize.height, cc.ResolutionPolicy.FIXED_HEIGHT)
local fileUtils = cc.FileUtils:getInstance()
local function addSearchPath(resPrefix, height) local function addSearchPath(resPrefix, height)
local searchPaths = fileUtils:getSearchPaths() local searchPaths = fileUtils:getSearchPaths()
table.insert(searchPaths, 1, resPrefix) table.insert(searchPaths, 1, resPrefix)