From c801d1868ccb621a05a9fa54f367e37fd3dfa278 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Tue, 28 Apr 2015 11:27:50 +0800 Subject: [PATCH] Update Sprite3DTest and VideoPlayerTest about Lua --- .../lua-bindings/script/3d/3dConstants.lua | 7 +++ .../src/Sprite3DTest/Sprite3DTest.lua | 45 +++++++++++++++++-- .../src/VideoPlayerTest/VideoPlayerTest.lua | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/cocos/scripting/lua-bindings/script/3d/3dConstants.lua b/cocos/scripting/lua-bindings/script/3d/3dConstants.lua index cd7a90f2a4..cd0d6022c3 100644 --- a/cocos/scripting/lua-bindings/script/3d/3dConstants.lua +++ b/cocos/scripting/lua-bindings/script/3d/3dConstants.lua @@ -7,3 +7,10 @@ cc.Terrain.CrackFixedType = SKIRT = 0, INCREASE_LOWER = 1, } + +cc.Animate3DQuality = +{ + QUALITY_NONE = 0, + QUALITY_LOW = 1, + QUALITY_HIGH = 2, +} diff --git a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua index 202c599b9f..082a0f3b2d 100644 --- a/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua +++ b/tests/lua-tests/src/Sprite3DTest/Sprite3DTest.lua @@ -1,3 +1,5 @@ +require "cocos.3d.3dConstants" + local size = cc.Director:getInstance():getWinSize() local scheduler = cc.Director:getInstance():getScheduler() local attributeNames = @@ -140,6 +142,8 @@ end ---------------------------------------- local Sprite3DWithSkinTest = {} Sprite3DWithSkinTest.__index = Sprite3DWithSkinTest +Sprite3DWithSkinTest._animateQuality = cc.Animate3DQuality.QUALITY_HIGH +Sprite3DWithSkinTest._sprites = {} function Sprite3DWithSkinTest.onTouchesEnd(touches, event) for i = 1,table.getn(touches) do @@ -154,6 +158,7 @@ function Sprite3DWithSkinTest.addNewSpriteWithCoords(parent,x,y) sprite:setRotation3D({x = 0, y = 180, z = 0}) sprite:setPosition(cc.p(x, y)) parent:addChild(sprite) + table.insert(Sprite3DWithSkinTest._sprites, sprite) local animation = cc.Animation3D:create("Sprite3DTest/orc.c3b") if nil ~= animation then @@ -177,8 +182,11 @@ function Sprite3DWithSkinTest.addNewSpriteWithCoords(parent,x,y) else animate:setSpeed(speed) end - - sprite:runAction(cc.RepeatForever:create(animate)) + animate:setTag(110) + animate:setQuality(Sprite3DWithSkinTest._animateQuality) + local repeate = cc.RepeatForever:create(animate) + repeate:setTag(110) + sprite:runAction(repeate) end end @@ -193,8 +201,39 @@ function Sprite3DWithSkinTest.create() local eventDispatcher = layer:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer) - + Sprite3DWithSkinTest._sprites = {} Sprite3DWithSkinTest.addNewSpriteWithCoords(layer, size.width / 2, size.height / 2) + + cc.MenuItemFont:setFontName("fonts/arial.ttf") + cc.MenuItemFont:setFontSize(15) + local menuItem = cc.MenuItemFont:create("High Quality") + Sprite3DWithSkinTest._animateQuality = cc.Animate3DQuality.QUALITY_HIGH + menuItem:registerScriptTapHandler(function(tag, sender) + Sprite3DWithSkinTest._animateQuality = Sprite3DWithSkinTest._animateQuality + 1 + + if Sprite3DWithSkinTest._animateQuality > cc.Animate3DQuality.QUALITY_HIGH then + Sprite3DWithSkinTest._animateQuality = cc.Animate3DQuality.QUALITY_NONE + end + + if Sprite3DWithSkinTest._animateQuality == cc.Animate3DQuality.QUALITY_NONE then + menuItem:setString("None Quality") + elseif Sprite3DWithSkinTest._animateQuality == cc.Animate3DQuality.QUALITY_LOW then + menuItem:setString("Low Quality") + elseif Sprite3DWithSkinTest._animateQuality == cc.Animate3DQuality.QUALITY_HIGH then + menuItem:setString("High Quality") + end + + for i,spriteIter in ipairs(Sprite3DWithSkinTest._sprites) do + local repAction = spriteIter:getActionByTag(110) + local animate3D = repAction:getInnerAction() + animate3D:setQuality(Sprite3DWithSkinTest._animateQuality) + end + end) + local menu = cc.Menu:create(menuItem) + menu:setPosition(cc.p(0.0, 0.0)) + menuItem:setPosition(VisibleRect:left().x + 50, VisibleRect:top().y -70) + layer:addChild(menu, 1) + return layer end diff --git a/tests/lua-tests/src/VideoPlayerTest/VideoPlayerTest.lua b/tests/lua-tests/src/VideoPlayerTest/VideoPlayerTest.lua index 8122f3c651..ee4279686e 100644 --- a/tests/lua-tests/src/VideoPlayerTest/VideoPlayerTest.lua +++ b/tests/lua-tests/src/VideoPlayerTest/VideoPlayerTest.lua @@ -106,7 +106,7 @@ local function VideoPlayerTest() local function menuOnlineVideoCallback(tag, sender) if nil ~= videoPlayer then - videoPlayer:setURL("http://video001.smgbb.cn/gslb/program/FDN/FDN1190949/HLSVodService.m3u8?_mdCode=6065719&_cdnCode=B2B_XL_TEST&_type=0&_rCode=TerOut_18865&_userId=020341000456068&_categoryCode=SMG_HUAYU&_categoryPath=SMG_1002,SMG_HUAYU,&_adPositionId=01001000&_adCategorySource=0&_flag=.m3u8&_enCode=m3u8&taskID=ysh_ps_002-ott_1397459105893_020341000456068&_client=103&_cms=ctv&_CDNToken=76C043FD4969501754DC19E54EC8DC2C") + videoPlayer:setURL("http://benchmark.cocos2d-x.org/cocosvideo.mp4") videoPlayer:play() end end