From e82074eb4fefec7a154f58a9e9ac8212cdf6ac21 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 13 Mar 2013 17:45:09 +0800 Subject: [PATCH] issue #1803:refactor lua codes --- .../ActionsEaseTest/ActionsEaseTest.lua | 153 ++------- .../ActionsProgressTest.lua | 145 ++------- .../luaScript/ActionsTest/ActionsName.lua | 48 --- .../luaScript/ActionsTest/ActionsTest.lua | 300 ++++++------------ .../DrawPrimitivesTest/DrawPrimitivesTest.lua | 84 +---- .../MotionStreakTest/MotionStreakTest.lua | 108 +------ .../Resources/luaScript/NodeTest/NodeTest.lua | 170 +++------- .../luaScript/SpriteTest/SpriteTest.lua | 235 ++++---------- .../TestLua/Resources/luaScript/helper.lua | 70 ++++ 9 files changed, 334 insertions(+), 979 deletions(-) delete mode 100644 samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsName.lua diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua index c1e2734078..0d0cfa790a 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua @@ -1,12 +1,7 @@ - -local SceneIdx = -1 -local MAX_LAYER = 13 - local kTagAction1 = 1 local kTagAction2 = 2 local kTagSlider = 1 -local titleLabel = nil local s = CCDirector:sharedDirector():getWinSize() local scheduler = CCDirector:sharedDirector():getScheduler() @@ -18,53 +13,6 @@ local function createSimpleDelayTime() return CCDelayTime:create(0.25) end -local function backAction() - SceneIdx = SceneIdx - 1 - if SceneIdx < 0 then - SceneIdx = SceneIdx + MAX_LAYER - end - - return CreateActionsEaseLayer() -end - -local function restartAction() - return CreateActionsEaseLayer() -end - -local function nextAction() - SceneIdx = SceneIdx + 1 - SceneIdx = math.mod(SceneIdx, MAX_LAYER) - - return CreateActionsEaseLayer() -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - local function positionForTwo() grossini:setPosition(CCPointMake(60, s.height * 1 / 5)) tamara:setPosition(CCPointMake(60, s.height * 4 / 5)) @@ -86,27 +34,7 @@ local function getBaseLayer() kathia:setPosition(CCPointMake(60, s.height * 2.5 / 5)) tamara:setPosition(CCPointMake(60, s.height * 4 / 5)) - titleLabel = CCLabelTTF:create("", "Arial", 32) - layer:addChild(titleLabel) - titleLabel:setPosition(s.width / 2, s.height - 50) - - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(s.width/2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(s.width/2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(s.width/2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - layer:addChild(menu, 1) + Helper.initWithLayer(layer) return layer end @@ -175,7 +103,7 @@ local function SpriteEase() layer:registerScriptHandler(SpriteEase_onEnterOrExit) - titleLabel:setString("EaseIn - EaseOut - Stop") + Helper.titleLabel:setString("EaseIn - EaseOut - Stop") return layer end @@ -223,7 +151,7 @@ local function SpriteEaseInOut() kathia:runAction(CCRepeatForever:create(seq2)) grossini:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("EaseInOut and rates") + Helper.titleLabel:setString("EaseInOut and rates") return layer end @@ -274,7 +202,7 @@ local function SpriteEaseExponential() tamara:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("ExpIn - ExpOut actions") + Helper.titleLabel:setString("ExpIn - ExpOut actions") return layer end @@ -314,7 +242,7 @@ local function SpriteEaseExponentialInOut() grossini:runAction(CCRepeatForever:create(seq1)) tamara:runAction(CCRepeatForever:create(seq2)) - titleLabel:setString("EaseExponentialInOut action") + Helper.titleLabel:setString("EaseExponentialInOut action") return layer end @@ -360,7 +288,7 @@ local function SpriteEaseSine() tamara:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("EaseSineIn - EaseSineOut") + Helper.titleLabel:setString("EaseSineIn - EaseSineOut") return layer end @@ -397,7 +325,7 @@ local function SpriteEaseSineInOut() grossini:runAction(CCRepeatForever:create(seq1)) tamara:runAction(CCRepeatForever:create(seq2)) - titleLabel:setString("EaseSineInOut action") + Helper.titleLabel:setString("EaseSineInOut action") return layer end @@ -443,7 +371,7 @@ local function SpriteEaseElastic() tamara:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("Elastic In - Out actions") + Helper.titleLabel:setString("Elastic In - Out actions") return layer end @@ -491,7 +419,7 @@ local function SpriteEaseElasticInOut() kathia:runAction(CCRepeatForever:create(seq2)) grossini:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("EaseElasticInOut action") + Helper.titleLabel:setString("EaseElasticInOut action") return layer end @@ -537,7 +465,7 @@ local function SpriteEaseBounce() tamara:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("Bounce In - Out actions") + Helper.titleLabel:setString("Bounce In - Out actions") return layer end @@ -574,7 +502,7 @@ local function SpriteEaseBounceInOut() grossini:runAction(CCRepeatForever:create(seq1)) tamara:runAction(CCRepeatForever:create(seq2)) - titleLabel:setString("EaseBounceInOut action") + Helper.titleLabel:setString("EaseBounceInOut action") return layer end @@ -620,7 +548,7 @@ local function SpriteEaseBack() tamara:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq3)) - titleLabel:setString("Back In - Out actions") + Helper.titleLabel:setString("Back In - Out actions") return layer end @@ -657,7 +585,7 @@ local function SpriteEaseBackInOut() grossini:runAction(CCRepeatForever:create(seq1)) tamara:runAction(CCRepeatForever:create(seq2)) - titleLabel:setString("EaseBackInOut action") + Helper.titleLabel:setString("EaseBackInOut action") return layer end @@ -709,48 +637,31 @@ local function SpeedTest() layer:registerScriptHandler(SpeedTest_onEnterOrExit) - titleLabel:setString("Speed action") + Helper.titleLabel:setString("Speed action") return layer end ------------------------------------ --- Actions Ease Test ------------------------------------ -function CreateActionsEaseLayer() - if SceneIdx == 0 then - return SpriteEase() - elseif SceneIdx == 1 then - return SpriteEaseInOut() - elseif SceneIdx == 2 then - return SpriteEaseExponential() - elseif SceneIdx == 3 then - return SpriteEaseExponentialInOut() - elseif SceneIdx == 4 then - return SpriteEaseSine() - elseif SceneIdx == 5 then - return SpriteEaseSineInOut() - elseif SceneIdx == 6 then - return SpriteEaseElastic() - elseif SceneIdx == 7 then - return SpriteEaseElasticInOut() - elseif SceneIdx == 8 then - return SpriteEaseBounce() - elseif SceneIdx == 9 then - return SpriteEaseBounceInOut() - elseif SceneIdx == 10 then - return SpriteEaseBack() - elseif SceneIdx == 11 then - return SpriteEaseBackInOut() - elseif SceneIdx == 12 then - return SpeedTest() - end -end - function EaseActionsTest() local scene = CCScene:create() + cclog("EaseActionsTest") - SceneIdx = -1 - scene:addChild(nextAction()) + Helper.createFunctionTable = { + SpriteEase, + SpriteEaseInOut, + SpriteEaseExponential, + SpriteEaseExponentialInOut, + SpriteEaseSine, + SpriteEaseSineInOut, + SpriteEaseElastic, + SpriteEaseElasticInOut, + SpriteEaseBounce, + SpriteEaseBounceInOut, + SpriteEaseBack, + SpriteEaseBackInOut, + SpeedTest + } + + scene:addChild(SpriteEase()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua index 4a973d5f71..496281dc95 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua @@ -1,90 +1,12 @@ -local SceneIdx = -1 -local MAX_LAYER = 7 local s = CCDirector:sharedDirector():getWinSize() -local function nextAction() - SceneIdx = SceneIdx + 1 - SceneIdx = math.mod(SceneIdx, MAX_LAYER) - return CreateActionProgressLayer() -end - -local function restartAction() - return CreateActionProgressLayer() -end - -local function backAction() - SceneIdx = SceneIdx - 1 - if SceneIdx < 0 then - SceneIdx = SceneIdx + MAX_LAYER - end - return CreateActionProgressLayer() -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function initWithLayer(layer) - titleLabel = CCLabelTTF:create("ActionsProgressTest", "Arial", 18) - layer:addChild(titleLabel, 1) - titleLabel:setPosition(s.width / 2, s.height - 50) - - subtitleLabel = CCLabelTTF:create("", "Thonburi", 22) - layer:addChild(subtitleLabel, 1) - subtitleLabel:setPosition(s.width / 2, s.height - 80) - - -- menu - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(s.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(s.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(s.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - layer:addChild(menu, 1) - - local background = CCLayerColor:create(ccc4(255,0,0,255)) - layer:addChild(background, -10) -end - ------------------------------------ -- SpriteProgressToRadial ------------------------------------ local function SpriteProgressToRadial() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to1 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100) @@ -103,7 +25,7 @@ local function SpriteProgressToRadial() right:runAction(CCRepeatForever:create(to2)) layer:addChild(right) - subtitleLabel:setString("ProgressTo Radial") + Helper.subtitleLabel:setString("ProgressTo Radial") return layer end @@ -112,7 +34,7 @@ end ------------------------------------ local function SpriteProgressToHorizontal() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to1 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100) @@ -137,7 +59,7 @@ local function SpriteProgressToHorizontal() right:runAction(CCRepeatForever:create(to2)) layer:addChild(right) - subtitleLabel:setString("ProgressTo Horizontal") + Helper.subtitleLabel:setString("ProgressTo Horizontal") return layer end @@ -146,7 +68,7 @@ end ------------------------------------ local function SpriteProgressToVertical() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to1 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100) @@ -172,7 +94,7 @@ local function SpriteProgressToVertical() right:runAction(CCRepeatForever:create(to2)) layer:addChild(right) - subtitleLabel:setString("ProgressTo Vertical") + Helper.subtitleLabel:setString("ProgressTo Vertical") return layer end @@ -181,7 +103,7 @@ end ------------------------------------ local function SpriteProgressToRadialMidpointChanged() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local action = CCProgressTo:create(2, 100) @@ -206,7 +128,7 @@ local function SpriteProgressToRadialMidpointChanged() right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100))) layer:addChild(right) - subtitleLabel:setString("Radial w/ Different Midpoints") + Helper.subtitleLabel:setString("Radial w/ Different Midpoints") return layer end @@ -215,7 +137,7 @@ end ------------------------------------ local function SpriteProgressBarVarious() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to = CCProgressTo:create(2, 100) @@ -250,7 +172,7 @@ local function SpriteProgressBarVarious() right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100))) layer:addChild(right) - subtitleLabel:setString("ProgressTo Bar Mid") + Helper.subtitleLabel:setString("ProgressTo Bar Mid") return layer end @@ -259,7 +181,7 @@ end ------------------------------------ local function SpriteProgressBarTintAndFade() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to = CCProgressTo:create(6, 100) local array = CCArray:create() @@ -318,7 +240,7 @@ local function SpriteProgressBarTintAndFade() right:addChild(CCLabelTTF:create("Tint and Fade", "Marker Felt", 20.0)) - subtitleLabel:setString("ProgressTo Bar Mid") + Helper.subtitleLabel:setString("ProgressTo Bar Mid") return layer end @@ -327,7 +249,7 @@ end ------------------------------------ local function SpriteProgressWithSpriteFrame() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local to = CCProgressTo:create(6, 100) @@ -363,41 +285,24 @@ local function SpriteProgressWithSpriteFrame() right:runAction(CCRepeatForever:create(CCProgressTo:create(6, 100))) layer:addChild(right) - subtitleLabel:setString("Progress With Sprite Frame") - return layer -end - ------------------------------------- --- Entrance ------------------------------------- -function CreateActionProgressLayer() - local layer = nil - - if SceneIdx == 0 then - layer = SpriteProgressToRadial() - elseif SceneIdx == 1 then - layer = SpriteProgressToHorizontal() - elseif SceneIdx == 2 then - layer = SpriteProgressToVertical() - elseif SceneIdx == 3 then - layer = SpriteProgressToRadialMidpointChanged() - elseif SceneIdx == 4 then - layer = SpriteProgressBarVarious() - elseif SceneIdx == 5 then - layer = SpriteProgressBarTintAndFade() - elseif SceneIdx == 6 then - layer = SpriteProgressWithSpriteFrame() - end - + Helper.subtitleLabel:setString("Progress With Sprite Frame") return layer end function ProgressActionsTest() - cclog("ProgressActionsTest") local scene = CCScene:create() - SceneIdx = -1 - scene:addChild(nextAction()) + Helper.createFunctionTable = { + SpriteProgressToRadial, + SpriteProgressToHorizontal, + SpriteProgressToVertical, + SpriteProgressToRadialMidpointChanged, + SpriteProgressBarVarious, + SpriteProgressBarTintAndFade, + SpriteProgressWithSpriteFrame + } + + scene:addChild(SpriteProgressToRadial()) scene:addChild(CreateBackMenuItem()) CCDirector:sharedDirector():replaceScene(scene) diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsName.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsName.lua deleted file mode 100644 index 5e174ada77..0000000000 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsName.lua +++ /dev/null @@ -1,48 +0,0 @@ -require "luaScript/helper" - - -Action_Table = -{ - "ACTION_MANUAL_LAYER", - "ACTION_MOVE_LAYER", - "ACTION_SCALE_LAYER", - "ACTION_ROTATE_LAYER", - "ACTION_SKEW_LAYER", - "ACTION_SKEW_STANDER", - "ACTION_SKEWROTATE_LAYER", - "ACTION_JUMP_LAYER", - "ACTION_CARDINALSPLINE_LAYER", - "ACTION_CATMULLROM_LAYER", - "ACTION_BEZIER_LAYER", - "ACTION_BLINK_LAYER", - "ACTION_FADE_LAYER", - "ACTION_TINT_LAYER", - "ACTION_ANIMATE_LAYER", - "ACTION_SEQUENCE_LAYER", - "ACTION_SEQUENCE2_LAYER", - "ACTION_SPAWN_LAYER", - "ACTION_REVERSE", - "ACTION_DELAYTIME_LAYER", - "ACTION_REPEAT_LAYER", - "ACTION_REPEATEFOREVER_LAYER", - "ACTION_ROTATETOREPEATE_LAYER", - "ACTION_ROTATEJERK_LAYER", - "ACTION_CALLFUNC_LAYER", --- problem: no corresponding function in CCLuaEngine yet --- "ACTION_CALLFUNCND_LAYER", - "ACTION_REVERSESEQUENCE_LAYER", - "ACTION_REVERSESEQUENCE2_LAYER", - "ACTION_ORBIT_LAYER", - "ACTION_FOLLOW_LAYER", - "ACTION_TARGETED_LAYER", --- problem: crash - "PAUSERESUMEACTIONS_LAYER", - "ACTION_ISSUE1305_LAYER", - "ACTION_ISSUE1305_2_LAYER", - "ACTION_ISSUE1288_LAYER", - "ACTION_ISSUE1288_2_LAYER", - "ACTION_ISSUE1327_LAYER", - "ACTION_LAYER_COUNT", -} - -Action_Table = CreateEnumTable(Action_Table) diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua index f5730b4b52..7a7eb53811 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionsTest/ActionsTest.lua @@ -1,59 +1,8 @@ require "luaScript/ActionsTest/ActionsName" -local ActionIdx = -1 local size = CCDirector:sharedDirector():getWinSize() -local titleLabel = nil -local subtitleLabel = nil - -local function BackAction() - ActionIdx = ActionIdx - 1 - if ActionIdx < 0 then - ActionIdx = ActionIdx + Action_Table.ACTION_LAYER_COUNT - end - - return CreateActionTestLayer() -end - -local function RestartAction() - return CreateActionTestLayer() -end - -local function NextAction() - ActionIdx = ActionIdx + 1 - ActionIdx = math.mod(ActionIdx, Action_Table.ACTION_LAYER_COUNT) - - return CreateActionTestLayer() -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(BackAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(RestartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(NextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - local function initWithLayer(layer) grossini = CCSprite:create(s_pPathGrossini) tamara = CCSprite:create(s_pPathSister1) @@ -67,31 +16,7 @@ local function initWithLayer(layer) tamara:setPosition(ccp(size.width / 2, 2 * size.height / 3)) kathia:setPosition(ccp(size.width / 2, size.height / 2)) - -- create title and subtitle - titleLabel = CCLabelTTF:create("ActionsTest", "Arial", 18) - titleLabel:setPosition(size.width/2, size.height - 30) - subtitleLabel = CCLabelTTF:create("", "Thonburi", 22) - subtitleLabel:setPosition(size.width / 2, size.height - 60) - layer:addChild(titleLabel, 1) - layer:addChild(subtitleLabel, 1) - - -- add menu - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - item1:setPosition(ccp(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(ccp(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(ccp(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - menu:setPosition(ccp(0, 0)) - layer:addChild(menu, 1) + Helper.initWithLayer(layer) end @@ -151,7 +76,7 @@ local function ActionManual() kathia:setPosition(ccp(size.width - 100, size.height / 2)) kathia:setColor(ccc3(0, 0, 255)) - subtitleLabel:setString("Manual Transformation") + Helper.subtitleLabel:setString("Manual Transformation") return layer end @@ -170,7 +95,7 @@ local function ActionMove() grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) kathia:runAction(CCMoveTo:create(1, ccp(40, 40))) - subtitleLabel:setString("MoveTo / MoveBy") + Helper.subtitleLabel:setString("MoveTo / MoveBy") return layer end @@ -191,7 +116,7 @@ local function ActionScale() tamara:runAction(CCSequence:createWithTwoActions(actionBy, actionBy:reverse())) kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse())) - subtitleLabel:setString("ScaleTo / ScaleBy") + Helper.subtitleLabel:setString("ScaleTo / ScaleBy") return layer end @@ -217,7 +142,7 @@ local function ActionRotate() kathia:runAction(CCSequence:createWithTwoActions(actionTo2, action0Retain)) - subtitleLabel:setString("RotateTo / RotateBy") + Helper.subtitleLabel:setString("RotateTo / RotateBy") return layer end @@ -240,7 +165,7 @@ local function ActionSkew() grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse())) - subtitleLabel:setString("SkewTo / SkewBy") + Helper.subtitleLabel:setString("SkewTo / SkewBy") return layer end @@ -285,7 +210,7 @@ local function ActionRotationalSkewVSStandardSkew() seq = CCSequence:createWithTwoActions(actionTo2, actionToBack2) box:runAction(seq); - subtitleLabel:setString("Skew Comparison") + Helper.subtitleLabel:setString("Skew Comparison") return layer; end @@ -333,7 +258,7 @@ local function ActionSkewRotate() box:runAction(CCSequence:createWithTwoActions(rotateTo, rotateToBack)) box:runAction(CCSequence:createWithTwoActions(actionScaleTo, actionScaleToBack)) - subtitleLabel:setString("Skew + Rotate + Scale") + Helper.subtitleLabel:setString("Skew + Rotate + Scale") return layer end @@ -355,7 +280,7 @@ local function ActionJump() grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) kathia:runAction(CCRepeatForever:create(actionUp)) - subtitleLabel:setString("JumpTo / JumpBy") + Helper.subtitleLabel:setString("JumpTo / JumpBy") return layer end @@ -403,8 +328,8 @@ local function ActionCardinalSpline() drawCardinalSpline(array) - titleLabel:setString("CardinalSplineBy / CardinalSplineAt") - subtitleLabel:setString("Cardinal Spline paths.\nTesting different tensions for one array") + Helper.titleLabel:setString("CardinalSplineBy / CardinalSplineAt") + Helper.subtitleLabel:setString("Cardinal Spline paths.\nTesting different tensions for one array") return layer end @@ -456,8 +381,8 @@ local function ActionCatmullRom() drawCatmullRom(array, array2) - titleLabel:setString("CatmullRomBy / CatmullRomTo") - subtitleLabel:setString("Catmull Rom spline paths. Testing reverse too") + Helper.titleLabel:setString("CatmullRomBy / CatmullRomTo") + Helper.subtitleLabel:setString("Catmull Rom spline paths. Testing reverse too") return layer end @@ -497,7 +422,7 @@ local function ActionBezier() tamara:runAction(bezierTo1) kathia:runAction(bezierTo2) - subtitleLabel:setString("BezierTo / BezierBy") + Helper.subtitleLabel:setString("BezierTo / BezierBy") return layer end @@ -516,7 +441,7 @@ local function ActionBlink() tamara:runAction(action1) kathia:runAction(action2) - subtitleLabel:setString("Blink") + Helper.subtitleLabel:setString("Blink") return layer end @@ -540,7 +465,7 @@ local function ActionFade() tamara:runAction(CCSequence:createWithTwoActions( action1, action1Back)) kathia:runAction(CCSequence:createWithTwoActions( action2, action2Back)) - subtitleLabel:setString("FadeIn / FadeOut") + Helper.subtitleLabel:setString("FadeIn / FadeOut") return layer end @@ -561,7 +486,7 @@ local function ActionTint() tamara:runAction(action1) kathia:runAction(CCSequence:createWithTwoActions(action2, action2Back)) - subtitleLabel:setString("TintTo / TintBy") + Helper.subtitleLabel:setString("TintTo / TintBy") return layer end @@ -607,8 +532,8 @@ local function ActionAnimate() local action3 = CCAnimate:create(animation3) kathia:runAction(action3) - titleLabel:setString("Animation") - subtitleLabel:setString("Center: Manual animation. Border: using file format animation") + Helper.titleLabel:setString("Animation") + Helper.subtitleLabel:setString("Center: Manual animation. Border: using file format animation") return layer end @@ -628,7 +553,7 @@ local function ActionSequence() grossini:runAction(action) - subtitleLabel:setString("Sequence: Move + Rotate") + Helper.subtitleLabel:setString("Sequence: Move + Rotate") return layer end @@ -677,7 +602,7 @@ local function ActionSequence2() grossini:runAction(action) - subtitleLabel:setString("Sequence of InstantActions") + Helper.subtitleLabel:setString("Sequence of InstantActions") return actionSequenceLayer end @@ -696,7 +621,7 @@ local function ActionSpawn() grossini:runAction(action) - subtitleLabel:setString("Spawn: Jump + Rotate") + Helper.subtitleLabel:setString("Spawn: Jump + Rotate") return layer end @@ -715,7 +640,7 @@ local function ActionReverse() grossini:runAction(action) - subtitleLabel:setString("Reverse an action") + Helper.subtitleLabel:setString("Reverse an action") return layer end @@ -738,7 +663,7 @@ local function ActionDelaytime() grossini:runAction(action) - subtitleLabel:setString("DelayTime: m + delay + m") + Helper.subtitleLabel:setString("DelayTime: m + delay + m") return layer end @@ -760,7 +685,7 @@ local function ActionRepeat() kathia:runAction(action1) tamara:runAction(action2) - subtitleLabel:setString("Repeat / RepeatForever actions") + Helper.subtitleLabel:setString("Repeat / RepeatForever actions") return layer end @@ -785,7 +710,7 @@ local function ActionRepeatForever() grossini:runAction(action) - subtitleLabel:setString("CallFuncN + RepeatForever") + Helper.subtitleLabel:setString("CallFuncN + RepeatForever") return layer end @@ -807,7 +732,7 @@ local function ActionRotateToRepeat() tamara:runAction(rep1) kathia:runAction(rep2) - subtitleLabel:setString("Repeat/RepeatForever + RotateTo") + Helper.subtitleLabel:setString("Repeat/RepeatForever + RotateTo") return layer end @@ -836,7 +761,7 @@ local function ActionRotateJerk() tamara:runAction(rep1) kathia:runAction(rep2) - subtitleLabel:setString("RepeatForever / Repeat + Rotate") + Helper.subtitleLabel:setString("RepeatForever / Repeat + Rotate") return layer end @@ -892,7 +817,7 @@ local function ActionCallFunc() tamara:runAction(action2) kathia:runAction(action3) - subtitleLabel:setString("Callbacks: CallFunc and friends") + Helper.subtitleLabel:setString("Callbacks: CallFunc and friends") return callFuncLayer end @@ -908,8 +833,8 @@ local function ActionCallFuncND() centerSprites(1) - titleLabel:setString("CallFuncND + auto remove") - subtitleLabel:setString("CallFuncND + removeFromParentAndCleanup. Grossini dissapears in 2s") + Helper.titleLabel:setString("CallFuncND + auto remove") + Helper.subtitleLabel:setString("CallFuncND + removeFromParentAndCleanup. Grossini dissapears in 2s") return layer end @@ -933,7 +858,7 @@ local function ActionReverseSequence() grossini:runAction(action) - subtitleLabel:setString("Reverse a sequence") + Helper.subtitleLabel:setString("Reverse a sequence") return layer end @@ -976,7 +901,7 @@ local function ActionReverseSequence2() local seq_back = seq_tamara:reverse() tamara:runAction(CCSequence:createWithTwoActions(seq_tamara, seq_back)) - subtitleLabel:setString("Reverse a sequence2") + Helper.subtitleLabel:setString("Reverse a sequence2") return layer end @@ -1011,7 +936,7 @@ local function ActionOrbit() grossini:runAction(tolua.cast(rfe:copy():autorelease(), "CCActionInterval")) - subtitleLabel:setString("OrbitCamera action") + Helper.subtitleLabel:setString("OrbitCamera action") return layer end @@ -1034,7 +959,7 @@ local function ActionFollow() layer:runAction(CCFollow:create(grossini, CCRectMake(0, 0, size.width * 2 - 100, size.height))) - subtitleLabel:setString("Follow action") + Helper.subtitleLabel:setString("Follow action") return layer end @@ -1065,8 +990,8 @@ local function ActionTargeted() tamara:runAction(always) - titleLabel:setString("ActionTargeted") - subtitleLabel:setString("Action that runs on another target. Useful for sequences") + Helper.titleLabel:setString("ActionTargeted") + Helper.subtitleLabel:setString("Action that runs on another target. Useful for sequences") return layer end @@ -1125,8 +1050,8 @@ local function PauseResumeActions() layer:registerScriptHandler(PauseResumeActions_onEnterOrExit) - titleLabel:setString("PauseResumeActions") - subtitleLabel:setString("All actions pause at 3s and resume at 5s") + Helper.titleLabel:setString("PauseResumeActions") + Helper.subtitleLabel:setString("All actions pause at 3s and resume at 5s") return layer end @@ -1169,8 +1094,8 @@ local function ActionIssue1305() Issue1305_layer:registerScriptHandler(Issue1305_onEnterOrExit) - titleLabel:setString("Issue 1305") - subtitleLabel:setString("In two seconds you should see a message on the console. NOT BEFORE.") + Helper.titleLabel:setString("Issue 1305") + Helper.subtitleLabel:setString("In two seconds you should see a message on the console. NOT BEFORE.") return Issue1305_layer end @@ -1225,8 +1150,8 @@ local function ActionIssue1305_2() CCDirector:sharedDirector():getActionManager():addAction(actF ,spr, false) - titleLabel:setString("Issue 1305 #2") - subtitleLabel:setString("See console. You should only see one message for each block") + Helper.titleLabel:setString("Issue 1305 #2") + Helper.subtitleLabel:setString("See console. You should only see one message for each block") return layer end @@ -1250,8 +1175,8 @@ local function ActionIssue1288() spr:runAction(act4) - titleLabel:setString("Issue 1288") - subtitleLabel:setString("Sprite should end at the position where it started.") + Helper.titleLabel:setString("Issue 1288") + Helper.subtitleLabel:setString("Sprite should end at the position where it started.") return layer end @@ -1271,8 +1196,8 @@ local function ActionIssue1288_2() local act1 = CCMoveBy:create(0.5, ccp(100, 0)) spr:runAction(CCRepeat:create(act1, 1)) - titleLabel:setString("Issue 1288 #2") - subtitleLabel:setString("Sprite should move 100 pixels, and stay there") + Helper.titleLabel:setString("Issue 1288 #2") + Helper.subtitleLabel:setString("Sprite should move 100 pixels, and stay there") return layer end @@ -1315,92 +1240,8 @@ local function ActionIssue1327() array:addObject(act9) spr:runAction(CCSequence:create(array)) - titleLabel:setString("Issue 1327") - subtitleLabel:setString("See console: You should see: 0, 45, 90, 135, 180") - return layer -end - -------------------------------------- --- Create Action Test -------------------------------------- -function CreateActionTestLayer() - local layer = nil - if ActionIdx == Action_Table.ACTION_MANUAL_LAYER then - layer = ActionManual() - elseif ActionIdx == Action_Table.ACTION_MOVE_LAYER then - layer = ActionMove() - elseif ActionIdx == Action_Table.ACTION_SCALE_LAYER then - layer = ActionScale() - elseif ActionIdx == Action_Table.ACTION_ROTATE_LAYER then - layer = ActionRotate() - elseif ActionIdx == Action_Table.ACTION_SKEW_LAYER then - layer = ActionSkew() - elseif ActionIdx == Action_Table.ACTION_SKEW_STANDER then - layer = ActionRotationalSkewVSStandardSkew() - elseif ActionIdx == Action_Table.ACTION_SKEWROTATE_LAYER then - layer = ActionSkewRotate() - elseif ActionIdx == Action_Table.ACTION_JUMP_LAYER then - layer = ActionJump() - elseif ActionIdx == Action_Table.ACTION_CARDINALSPLINE_LAYER then - layer = ActionCardinalSpline() - elseif ActionIdx == Action_Table.ACTION_CATMULLROM_LAYER then - layer = ActionCatmullRom() - elseif ActionIdx == Action_Table.ACTION_BEZIER_LAYER then - layer = ActionBezier() - elseif ActionIdx == Action_Table.ACTION_BLINK_LAYER then - layer = ActionBlink() - elseif ActionIdx == Action_Table.ACTION_FADE_LAYER then - layer = ActionFade() - elseif ActionIdx == Action_Table.ACTION_TINT_LAYER then - layer = ActionTint() - elseif ActionIdx == Action_Table.ACTION_ANIMATE_LAYER then - layer = ActionAnimate() - elseif ActionIdx == Action_Table.ACTION_SEQUENCE_LAYER then - layer = ActionSequence() - elseif ActionIdx == Action_Table.ACTION_SEQUENCE2_LAYER then - layer = ActionSequence2() - elseif ActionIdx == Action_Table.ACTION_SPAWN_LAYER then - layer = ActionSpawn() - elseif ActionIdx == Action_Table.ACTION_REVERSE then - layer = ActionReverse() - elseif ActionIdx == Action_Table.ACTION_DELAYTIME_LAYER then - layer = ActionDelaytime() - elseif ActionIdx == Action_Table.ACTION_REPEAT_LAYER then - layer = ActionRepeat() - elseif ActionIdx == Action_Table.ACTION_REPEATEFOREVER_LAYER then - layer = ActionRepeatForever() - elseif ActionIdx == Action_Table.ACTION_ROTATETOREPEATE_LAYER then - layer = ActionRotateToRepeat() - elseif ActionIdx == Action_Table.ACTION_ROTATEJERK_LAYER then - layer = ActionRotateJerk() - elseif ActionIdx == Action_Table.ACTION_CALLFUNC_LAYER then - layer = ActionCallFunc() - elseif ActionIdx == Action_Table.ACTION_CALLFUNCND_LAYER then - layer = ActionCallFuncND() - elseif ActionIdx == Action_Table.ACTION_REVERSESEQUENCE_LAYER then - layer = ActionReverseSequence() - elseif ActionIdx == Action_Table.ACTION_REVERSESEQUENCE2_LAYER then - layer = ActionReverseSequence2() - elseif ActionIdx == Action_Table.ACTION_ORBIT_LAYER then - layer = ActionOrbit() - elseif ActionIdx == Action_Table.ACTION_FOLLOW_LAYER then - layer = ActionFollow() - elseif ActionIdx == Action_Table.ACTION_TARGETED_LAYER then - layer = ActionTargeted() - elseif ActionIdx == Action_Table.PAUSERESUMEACTIONS_LAYER then - layer = PauseResumeActions() - elseif ActionIdx == Action_Table.ACTION_ISSUE1305_LAYER then - layer = ActionIssue1305() - elseif ActionIdx == Action_Table.ACTION_ISSUE1305_2_LAYER then - layer = ActionIssue1305_2() - elseif ActionIdx == Action_Table.ACTION_ISSUE1288_LAYER then - layer = ActionIssue1288() - elseif ActionIdx == Action_Table.ACTION_ISSUE1288_2_LAYER then - layer = ActionIssue1288_2() - elseif ActionIdx == Action_Table.ACTION_ISSUE1327_LAYER then - layer = ActionIssue1327() - end - + Helper.titleLabel:setString("Issue 1327") + Helper.subtitleLabel:setString("See console: You should see: 0, 45, 90, 135, 180") return layer end @@ -1408,8 +1249,47 @@ function ActionsTest() cclog("ActionsTest") local scene = CCScene:create() - ActionIdx = -1 - scene:addChild(NextAction()) + Helper.createFunctionTable = { + ActionManual, + ActionMove, + ActionScale, + ActionRotate, + ActionSkew, + ActionRotationalSkewVSStandardSkew, + ActionSkewRotate, + ActionJump, + ActionCardinalSpline, + ActionCatmullRom, + ActionBezier, + ActionBlink, + ActionFade, + ActionTint, + ActionAnimate, + ActionSequence, + ActionSequence2, + ActionSpawn, + ActionReverse, + ActionDelaytime, + ActionRepeat, + ActionRepeatForever, + ActionRotateToRepeat, + ActionRotateJerk, + ActionCallFunc, + ActionCallFuncND, + ActionReverseSequence, + ActionReverseSequence2, + ActionOrbit, + ActionFollow, + ActionTargeted, + PauseResumeActions, + ActionIssue1305, + ActionIssue1305_2, + ActionIssue1288, + ActionIssue1288_2, + ActionIssue1327 + } + + scene:addChild(ActionManual()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua index 454ec68933..09eb761955 100644 --- a/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/DrawPrimitivesTest/DrawPrimitivesTest.lua @@ -5,73 +5,13 @@ local MAX_LAYER = 2 local background = nil local labelAtlas = nil -local titleLabel = nil -local subtitleLabel = nil local baseLayer_entry = nil local s = CCDirector:sharedDirector():getWinSize() - -local function backAction() - SceneIdx = SceneIdx - 1 - if SceneIdx < 0 then - SceneIdx = SceneIdx + MAX_LAYER - end - - return CreateParticleLayer() -end - -local function restartAction() - return CreateParticleLayer() -end - -local function nextAction() - SceneIdx = SceneIdx + 1 - SceneIdx = math.mod(SceneIdx, MAX_LAYER) - - return CreateDrawPrimitivesTestLayer() -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - - local function getBaseLayer() local layer = CCLayer:create() - titleLabel = CCLabelTTF:create("", "Arial", 28) - layer:addChild(titleLabel, 100, 1000) - titleLabel:setPosition(s.width / 2, s.height - 50) - - subtitleLabel = CCLabelTTF:create("", "Arial", 16) - layer:addChild(subtitleLabel, 100) - subtitleLabel:setPosition(s.width / 2, s.height - 80) - - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) @@ -82,27 +22,14 @@ local function getBaseLayer() item2:registerScriptTapHandler(restartCallback) item3:registerScriptTapHandler(nextCallback) - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - menu:addChild(item4) - - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(s.width/2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(s.width/2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(s.width/2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item4:setPosition(ccp(0, 100)) - item4:setAnchorPoint(ccp(0, 0)) - - layer:addChild(menu, 100) - labelAtlas = CCLabelAtlas:create("0000", "fps_images.png", 12, 32, string.byte('.')) layer:addChild(labelAtlas, 100) labelAtlas:setPosition(ccp(s.width - 66, 50)) layer:setTouchEnabled(false) + Helper.initWithLayer(layer) + return layer end @@ -199,8 +126,11 @@ function DrawPrimitivesTest() cclog("DrawPrimitivesTest") local scene = CCScene:create() - SceneIdx = -1 - scene:addChild(nextAction()) + Helper.createFunctionTable = { + drawPrimitivesTest + } + + scene:addChild(drawPrimitivesTest()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua b/samples/Lua/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua index b955bc7a9b..ba57c64701 100644 --- a/samples/Lua/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/MotionStreakTest/MotionStreakTest.lua @@ -1,7 +1,4 @@ -local SceneIdx = 0 -local MAX_LAYER = 3 - local streak = nil local titleLabel = nil local subtitleLabel = nil @@ -11,26 +8,6 @@ local scheduler = CCDirector:sharedDirector():getScheduler() local firstTick = nil -local function backAction() - SceneIdx = SceneIdx - 1 - if SceneIdx < 0 then - SceneIdx = SceneIdx + MAX_LAYER - end - - return CreateMotionLayer() -end - -local function restartAction() - return CreateParticleLayer() -end - -local function nextAction() - SceneIdx = SceneIdx + 1 - SceneIdx = math.mod(SceneIdx, MAX_LAYER) - - return CreateMotionLayer() -end - local function modeCallback(sender) fastMode = streak:isFastMode() if fastMode == true then @@ -40,62 +17,9 @@ local function modeCallback(sender) end end -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - local function getBaseLayer() local layer = CCLayer:create() - titleLabel = CCLabelTTF:create("", "Arial", 32) - layer:addChild(titleLabel, 0) - titleLabel:setPosition(s.width / 2, s.height - 50) - - subtitleLabel = CCLabelTTF:create("", "Thonburi", 16) - layer:addChild(subtitleLabel, 1) - subtitleLabel:setPosition(s.width / 2, s.height - 80) - - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(s.width/2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(s.width/2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(s.width/2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - layer:addChild(menu, 1) - local itemMode = CCMenuItemToggle:create(CCMenuItemFont:create("Use High Quality Mode")) itemMode:addSubItem(CCMenuItemFont:create("Use Fast Mode")) itemMode:registerScriptTapHandler(modeCallback) @@ -104,6 +28,8 @@ local function getBaseLayer() menuMode:setPosition(ccp(s.width / 2, s.height / 4)) layer:addChild(menuMode) + Helper.initWithLayer(layer) + return layer end @@ -167,7 +93,7 @@ local function MotionStreakTest1() firstTick = true layer:registerScriptHandler(MotionStreakTest1_onEnterOrExit) - titleLabel:setString("MotionStreak test 1") + Helper.titleLabel:setString("MotionStreak test 1") return layer end @@ -203,7 +129,7 @@ local function MotionStreakTest2() layer:setTouchEnabled(true) layer:registerScriptTouchHandler(onTouch) - titleLabel:setString("MotionStreak test") + Helper.titleLabel:setString("MotionStreak test") return layer end @@ -247,29 +173,21 @@ local function Issue1358() firstTick = true layer:registerScriptHandler(Issue1358_onEnterOrExit) - titleLabel:setString("Issue 1358") - subtitleLabel:setString("The tail should use the texture") + Helper.titleLabel:setString("Issue 1358") + Helper.subtitleLabel:setString("The tail should use the texture") return layer end ------------------------------------ --- Motion Streak Test ------------------------------------ -function CreateMotionLayer() - if SceneIdx == 0 then - return MotionStreakTest1() - elseif SceneIdx == 1 then - return MotionStreakTest2() - elseif SceneIdx == 2 then - return Issue1358() - end -end - function MotionStreakTest() local scene = CCScene:create() - SceneIdx = -1 - scene:addChild(nextAction()) + Helper.createFunctionTable = { + MotionStreakTest1, + MotionStreakTest2, + Issue1358 + } + + scene:addChild(MotionStreakTest1()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua b/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua index cb465c8182..f72acf6c6c 100644 --- a/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua @@ -1,94 +1,17 @@ - -local SceneIdx = -1 -local MAX_LAYER = 13 - local kTagSprite1 = 1 local kTagSprite2 = 2 local kTagSprite3 = 3 local kTagSlider = 4 -local titleLabel = nil -local subTitleLabel = nil local s = CCDirector:sharedDirector():getWinSize() local scheduler = CCDirector:sharedDirector():getScheduler() -local function backAction() - SceneIdx = SceneIdx - 1 - if SceneIdx < 0 then - SceneIdx = SceneIdx + MAX_LAYER - end - - return CreateNodeTestLayer() -end - -local function restartAction() - return CreateNodeTestLayer() -end - -local function nextAction() - SceneIdx = SceneIdx + 1 - SceneIdx = math.mod(SceneIdx, MAX_LAYER) - - return CreateNodeTestLayer() -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - local function getBaseLayer() local layer = CCLayer:create() - titleLabel = CCLabelTTF:create("", "Arial", 32) - layer:addChild(titleLabel, 10) - titleLabel:setPosition(s.width / 2, s.height - 50) + Helper.initWithLayer(layer) - subTitleLabel = CCLabelTTF:create("", "Thonburi", 16) - layer:addChild(subTitleLabel, 1) - subTitleLabel:setPosition(s.width / 2, s.height - 80) - - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(s.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(s.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(s.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - layer:addChild(menu, 11) - - return layer + return layer end ----------------------------------- @@ -143,8 +66,8 @@ local function CameraCenterTest() orbit = CCOrbitCamera:create(10, 1, 0, 0, 360, 0, 0) sprite:runAction(CCRepeatForever:create(orbit)) - titleLabel:setString("Camera Center test") - subTitleLabel:setString("Sprites should rotate at the same speed") + Helper.titleLabel:setString("Camera Center test") + Helper.subtitleLabel:setString("Sprites should rotate at the same speed") return layer end @@ -189,7 +112,7 @@ local function Test2() sp1:runAction(action1) sp2:runAction(action2) - titleLabel:setString("anchorPoint and children") + Helper.titleLabel:setString("anchorPoint and children") return layer end @@ -234,7 +157,7 @@ local function Test4() Test4_layer:registerScriptHandler(Test4_onEnterOrExit) - titleLabel:setString("tags") + Helper.titleLabel:setString("tags") return Test4_layer end @@ -297,7 +220,7 @@ local function Test5() Test5_layer:registerScriptHandler(Test5_onEnterOrExit) - titleLabel:setString("remove and cleanup") + Helper.titleLabel:setString("remove and cleanup") return Test5_layer end @@ -364,7 +287,7 @@ local function Test6() Test6_layer:registerScriptHandler(Test6_onEnterOrExit) - titleLabel:setString("remove/cleanup with children") + Helper.titleLabel:setString("remove/cleanup with children") return Test6_layer end @@ -377,7 +300,7 @@ local StressTest1_layer = nil local function removeMe(node) local parent = StressTest1_layer:getParent() parent:removeChild(node, true) - nextCallback(node) + Helper.nextAction() end local function shouldNotCrash(dt) @@ -413,7 +336,7 @@ local function StressTest1() StressTest1_layer:registerScriptHandler(StressTest1_onEnterOrExit) - titleLabel:setString("stress test #1: no crashes") + Helper.titleLabel:setString("stress test #1: no crashes") return StressTest1_layer end @@ -466,7 +389,7 @@ local function StressTest2() StressTest2_layer:addChild(sublayer, 0, kTagSprite1) - titleLabel:setString("stress test #2: no leaks") + Helper.titleLabel:setString("stress test #2: no leaks") return StressTest2_layer end @@ -502,7 +425,7 @@ local function NodeToWorld() local fe2 = CCRepeatForever:create(seq) back:runAction(fe2) - titleLabel:setString("nodeToParent transform") + Helper.titleLabel:setString("nodeToParent transform") return layer end @@ -558,7 +481,7 @@ local function CameraOrbitTest() layer:setScale(1) - titleLabel:setString("Camera Orbit test") + Helper.titleLabel:setString("Camera Orbit test") return layer end @@ -617,7 +540,7 @@ local function CameraZoomTest() CameraZoomTest_layer:scheduleUpdateWithPriorityLua(CameraZoomTest_update, 0) CameraZoomTest_layer:registerScriptHandler(CameraZoomTest_onEnterOrExit) - titleLabel:setString("Camera Zoom test") + Helper.titleLabel:setString("Camera Zoom test") return CameraZoomTest_layer end @@ -677,8 +600,8 @@ local function ConvertToNode() ConvertToNode_layer:setTouchEnabled(true) ConvertToNode_layer:registerScriptTouchHandler(onTouch) - titleLabel:setString("Convert To Node Space") - subTitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console") + Helper.titleLabel:setString("Convert To Node Space") + Helper.subtitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console") return ConvertToNode_layer end @@ -698,8 +621,8 @@ local function NodeOpaqueTest() layer:addChild(background) end - titleLabel:setString("Node Opaque Test") - subTitleLabel:setString("Node rendered with GL_BLEND disabled") + Helper.titleLabel:setString("Node Opaque Test") + Helper.subtitleLabel:setString("Node rendered with GL_BLEND disabled") return layer end @@ -718,50 +641,31 @@ local function NodeNonOpaqueTest() background:setAnchorPoint(ccp(0, 0)) layer:addChild(background) end - titleLabel:setString("Node Non Opaque Test") - subTitleLabel:setString("Node rendered with GL_BLEND enabled") + Helper.titleLabel:setString("Node Non Opaque Test") + Helper.subtitleLabel:setString("Node rendered with GL_BLEND enabled") return layer end ------------------------------------ --- Node Test ------------------------------------ -function CreateNodeTestLayer() - if SceneIdx == 0 then - return CameraCenterTest() - elseif SceneIdx == 1 then - return Test2() - elseif SceneIdx == 2 then - return Test4() - elseif SceneIdx == 3 then - return Test5() - elseif SceneIdx == 4 then - return Test6() - elseif SceneIdx == 5 then - return StressTest1() - elseif SceneIdx == 6 then - return StressTest2() - elseif SceneIdx == 7 then - return NodeToWorld() - elseif SceneIdx == 8 then - return CameraOrbitTest() - elseif SceneIdx == 9 then - return CameraZoomTest() - elseif SceneIdx == 10 then - return ConvertToNode() - elseif SceneIdx == 11 then - return NodeOpaqueTest() - elseif SceneIdx == 12 then - return NodeNonOpaqueTest() - end -end - function CocosNodeTest() - cclog("NodeTest") local scene = CCScene:create() - SceneIdx = -1 - scene:addChild(nextAction()) + Helper.createFunctionTable = { + CameraCenterTest, + Test2, + Test4, + Test5, + Test6, + StressTest1, + StressTest2, + NodeToWorld, + CameraOrbitTest, + CameraZoomTest, + ConvertToNode, + NodeOpaqueTest, + NodeNonOpaqueTest + } + + scene:addChild(CameraCenterTest()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua b/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua index d23e888203..c98d3e00c1 100644 --- a/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua @@ -1,9 +1,4 @@ - - -local ActionIdx = 0 -local createFunctionTable = nil local size = CCDirector:sharedDirector():getWinSize() - local kTagTileMap = 1 local kTagSpriteBatchNode = 1 local kTagNode = 2 @@ -21,108 +16,7 @@ local kTagSprite7 = 6 local kTagSprite8 = 7 local testLayer = nil -local titleLabel = nil local entry = nil -local subtitleLabel = nil - -local playerLayer = nil - -local function onEnterOrExit(tag) - local scheduler = CCDirector:sharedDirector():getScheduler() - if tag == "enter" then --- entry = scheduler:scheduleScriptFunc(checkAnim, 0, false) - elseif tag == "exit" then --- scheduler:unscheduleScriptEntry(entry) - end -end - -local function CreateSpriteTestLayer() - local layer = createFunctionTable[ActionIdx]() - - playerLayer = layer - return layer -end - -local function backAction() - ActionIdx = ActionIdx - 1 - if ActionIdx <= 0 then - ActionIdx = table.getn(createFunctionTable) - end - - return CreateSpriteTestLayer() -end - -local function restartAction() - return CreateSpriteTestLayer() -end - -local function nextAction() - ActionIdx = ActionIdx + 1 - if ActionIdx > table.getn(createFunctionTable) then - ActionIdx = 1 - end - - return CreateSpriteTestLayer() -end - -local function backCallback(sender) - local scene = CCScene:create() - - scene:addChild(backAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function restartCallback(sender) - local scene = CCScene:create() - - scene:addChild(restartAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - -local function nextCallback(sender) - local scene = CCScene:create() - - scene:addChild(nextAction()) - scene:addChild(CreateBackMenuItem()) - - CCDirector:sharedDirector():replaceScene(scene) -end - - -local function initWithLayer(layer) - titleLabel = CCLabelTTF:create("", "Arial", 28) - layer:addChild(titleLabel, 1) - titleLabel:setPosition(size.width / 2, size.height - 50) - - subtitleLabel = CCLabelTTF:create("", "Thonburi", 16) - layer:addChild(subtitleLabel, 1) - subtitleLabel:setPosition(size.width / 2, size.height - 80) - - -- menu - local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) - local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) - local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) - item1:registerScriptTapHandler(backCallback) - item2:registerScriptTapHandler(restartCallback) - item3:registerScriptTapHandler(nextCallback) - - local menu = CCMenu:create() - menu:addChild(item1) - menu:addChild(item2) - menu:addChild(item3) - menu:setPosition(CCPointMake(0, 0)) - item1:setPosition(CCPointMake(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - item2:setPosition(CCPointMake(size.width / 2, item2:getContentSize().height / 2)) - item3:setPosition(CCPointMake(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) - layer:addChild(menu, 1) - - local background = CCLayer:create() - layer:addChild(background, -10) -end -------------------------------------------- ---- test sprite1 @@ -165,7 +59,7 @@ function Sprite1.onTouch(event, x, y) if event == "began" then return true elseif event == "ended" then - Sprite1.addNewSpriteWithCoords(playerLayer, ccp(x,y)) + Sprite1.addNewSpriteWithCoords(Helper.currentLayer, ccp(x,y)) return true end end @@ -173,12 +67,12 @@ end function Sprite1.create() cclog("sprite1") local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) Sprite1.addNewSpriteWithCoords(layer, ccp(size.width/2, size.height/2)) layer:setTouchEnabled(true) layer:registerScriptTouchHandler(Sprite1.onTouch) - titleLabel:setString("Sprite (tap screen)") + Helper.titleLabel:setString("Sprite (tap screen)") return layer end @@ -225,14 +119,14 @@ function SpriteBatchNode1.onTouch(event, x, y) if event == "began" then return true elseif event == "ended" then - SpriteBatchNode1.addNewSpriteWithCoords(playerLayer, ccp(x,y)) + SpriteBatchNode1.addNewSpriteWithCoords(Helper.currentLayer, ccp(x,y)) return true end end function SpriteBatchNode1.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) local BatchNode = CCSpriteBatchNode:create("Images/grossini_dance_atlas.png", 50) layer:addChild(BatchNode, 0, kTagSpriteBatchNode) @@ -241,7 +135,7 @@ function SpriteBatchNode1.create() layer:setTouchEnabled(true) layer:registerScriptTouchHandler(SpriteBatchNode1.onTouch) - titleLabel:setString("SpriteBatchNode (tap screen)") + Helper.titleLabel:setString("SpriteBatchNode (tap screen)") return layer end @@ -308,29 +202,29 @@ function SpriteColorOpacity.setLayerSprite(layer) end function SpriteColorOpacity.onEnterOrExit(tag) - local schedule = CCDirector:sharedDirector():getScheduler() if tag == "enter" then - SpriteColorOpacity.entry = scheduler:scheduleScriptFunc(SpriteColorOpacity.removeAndAddSprite, 0, false) + SpriteColorOpacity.onEnter() elseif tag == "exit" then - scheduler:unscheduleScriptEntry(SpriteColorOpacity.entry) + SpriteColorOpacity.onExit() end end function SpriteColorOpacity.removeAndAddSprite(dt) - local sprite = playerLayer:getChildByTag(kTagSprite5) + local sprite = Helper.currentLayer:getChildByTag(kTagSprite5) sprite:retain() - playerLayer:removeChild(sprite, false) - playerLayer:addChild(sprite, 0, kTagSprite5) + Helper.currentLayer:removeChild(sprite, false) + Helper.currentLayer:addChild(sprite, 0, kTagSprite5) sprite:release() end function SpriteColorOpacity.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) SpriteColorOpacity.setLayerSprite(layer) - titleLabel:setString("Sprite: Color & Opacity") + layer:registerScriptHandler(SpriteColorOpacity.onEnterOrExit) + Helper.titleLabel:setString("Sprite: Color & Opacity") return layer end @@ -358,7 +252,7 @@ function SpriteFrameTest.onEnter() local spritebatch = CCSpriteBatchNode:create("animations/grossini.png") spritebatch:addChild(SpriteFrameTest.m_pSprite1) - playerLayer:addChild(spritebatch) + Helper.currentLayer:addChild(spritebatch) local animFrames = CCArray:createWithCapacity(15) for i = 1,14 do @@ -374,7 +268,7 @@ function SpriteFrameTest.onEnter() SpriteFrameTest.m_pSprite2 = CCSprite:createWithSpriteFrameName("grossini_dance_01.png") SpriteFrameTest.m_pSprite2:setPosition( ccp( s.width/2 + 80, s.height/2) ) - playerLayer:addChild(SpriteFrameTest.m_pSprite2) + Helper.currentLayer:addChild(SpriteFrameTest.m_pSprite2) local moreFrames = CCArray:createWithCapacity(20) for i = 1,14 do @@ -396,12 +290,8 @@ function SpriteFrameTest.onEnter() SpriteFrameTest.m_pSprite2:setFlipY(false) - performWithDelay(playerLayer,SpriteFrameTest.startIn05Secs, 0.5) + performWithDelay(Helper.currentLayer,SpriteFrameTest.startIn05Secs, 0.5) SpriteFrameTest.m_nCounter = 0 - - local scheduler = CCDirector:sharedDirector():getScheduler() - scheduler:unscheduleScriptEntry(SpriteFrameTest.entry) - end function SpriteFrameTest.onExit() @@ -412,7 +302,7 @@ function SpriteFrameTest.onExit() end function SpriteFrameTest.startIn05Secs(dt) - schedule(playerLayer,SpriteFrameTest.flipSprites, 1) + schedule(Helper.currentLayer,SpriteFrameTest.flipSprites, 1) end function SpriteFrameTest.flipSprites(dt) @@ -444,20 +334,19 @@ end function SpriteFrameTest.onEnterOrExit(tag) - local scheduler = CCDirector:sharedDirector():getScheduler() if tag == "enter" then - SpriteFrameTest.entry = scheduler:scheduleScriptFunc(SpriteFrameTest.onEnter, 0, false) + SpriteFrameTest.onEnter() elseif tag == "exit" then - scheduler:unscheduleScriptEntry(SpriteFrameTest.entry) + SpriteFrameTest.onExit() end end function SpriteFrameTest.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer:registerScriptHandler(SpriteFrameTest.onEnterOrExit) - titleLabel:setString("Sprite vs. SpriteBatchNode animation") + Helper.titleLabel:setString("Sprite vs. SpriteBatchNode animation") return layer end @@ -483,7 +372,7 @@ function SpriteFrameAliasNameTest.onEnter() cclog("spriteBatch = " .. tostring(tolua.isnull(spriteBatch))) cclog("sprite = " .. tostring(tolua.isnull(sprite))) spriteBatch:addChild(sprite) - playerLayer:addChild(spriteBatch) + Helper.currentLayer:addChild(spriteBatch) local animFrames = CCArray:createWithCapacity(15) for i = 1,14 do @@ -494,9 +383,6 @@ function SpriteFrameAliasNameTest.onEnter() local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3) -- 14 frames * 1sec = 14 seconds sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation))) - - local scheduler = CCDirector:sharedDirector():getScheduler() - scheduler:unscheduleScriptEntry(SpriteFrameAliasNameTest.entry) end function SpriteFrameAliasNameTest.onExit() @@ -504,21 +390,20 @@ function SpriteFrameAliasNameTest.onExit() end function SpriteFrameAliasNameTest.onEnterOrExit(tag) - local scheduler = CCDirector:sharedDirector():getScheduler() if tag == "enter" then - SpriteFrameAliasNameTest.entry = scheduler:scheduleScriptFunc(SpriteFrameAliasNameTest.onEnter, 0, false) + SpriteFrameAliasNameTest.onEnter() elseif tag == "exit" then - scheduler:unscheduleScriptEntry(SpriteFrameAliasNameTest.entry) + SpriteFrameAliasNameTest.onExit() end end function SpriteFrameAliasNameTest.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer:registerScriptHandler(SpriteFrameAliasNameTest.onEnterOrExit) - titleLabel:setString("SpriteFrame Alias Name") - subtitleLabel:setString("SpriteFrames are obtained using the alias name") + Helper.titleLabel:setString("SpriteFrame Alias Name") + Helper.subtitleLabel:setString("SpriteFrames are obtained using the alias name") return layer end @@ -565,11 +450,11 @@ end function SpriteAnchorPoint.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteAnchorPoint.initLayer(layer) - titleLabel:setString("Sprite: anchor point") - subtitleLabel:setString("") + Helper.titleLabel:setString("Sprite: anchor point") + Helper.subtitleLabel:setString("") return layer end @@ -618,11 +503,11 @@ end function SpriteBatchNodeAnchorPoint.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteBatchNodeAnchorPoint.initLayer(layer) - titleLabel:setString("SpriteBatchNode: anchor point") - subtitleLabel:setString("") + Helper.titleLabel:setString("SpriteBatchNode: anchor point") + Helper.subtitleLabel:setString("") return layer end @@ -682,11 +567,11 @@ end function SpriteOffsetAnchorRotation.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteOffsetAnchorRotation.initLayer(layer) - titleLabel:setString("Sprite offset + anchor + rot") - subtitleLabel:setString("") + Helper.titleLabel:setString("Sprite offset + anchor + rot") + Helper.subtitleLabel:setString("") return layer end @@ -751,11 +636,11 @@ end function SpriteBatchNodeOffsetAnchorRotation.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteBatchNodeOffsetAnchorRotation.initLayer(layer) - titleLabel:setString("SpriteBatchNode offset + anchor + rot") - subtitleLabel:setString("") + Helper.titleLabel:setString("SpriteBatchNode offset + anchor + rot") + Helper.subtitleLabel:setString("") return layer end @@ -820,11 +705,11 @@ end function SpriteOffsetAnchorScale.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteOffsetAnchorScale.initLayer(layer) - titleLabel:setString("Sprite offset + anchor + scale") - subtitleLabel:setString("") + Helper.titleLabel:setString("Sprite offset + anchor + scale") + Helper.subtitleLabel:setString("") return layer end @@ -902,12 +787,12 @@ end function SpriteBatchNodeOffsetAnchorScale.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorScale.eventHandler) layer = SpriteBatchNodeOffsetAnchorScale.initLayer(layer) - titleLabel:setString("SpriteBatchNode offset + anchor + scale") - subtitleLabel:setString("") + Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale") + Helper.subtitleLabel:setString("") return layer end @@ -981,11 +866,11 @@ end function SpriteOffsetAnchorSkew.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteOffsetAnchorSkew.initLayer(layer) - titleLabel:setString("SpriteBatchNode offset + anchor + scale") - subtitleLabel:setString("") + Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale") + Helper.subtitleLabel:setString("") return layer end @@ -1054,11 +939,11 @@ end function SpriteOffsetAnchorRotationalSkew.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteOffsetAnchorRotationalSkew.initLayer(layer) - titleLabel:setString("Sprite offset + anchor + rotational skew") - subtitleLabel:setString("") + Helper.titleLabel:setString("Sprite offset + anchor + rotational skew") + Helper.subtitleLabel:setString("") return layer end @@ -1133,11 +1018,11 @@ end function SpriteBatchNodeOffsetAnchorSkew.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteBatchNodeOffsetAnchorSkew.initLayer(layer) - titleLabel:setString("SpriteBatchNode offset + anchor + skew") - subtitleLabel:setString("") + Helper.titleLabel:setString("SpriteBatchNode offset + anchor + skew") + Helper.subtitleLabel:setString("") return layer end @@ -1212,11 +1097,11 @@ end function SpriteBatchNodeOffsetAnchorRotationalSkew.create() local layer = CCLayer:create() - initWithLayer(layer) + Helper.initWithLayer(layer) layer = SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer) - titleLabel:setString("SSpriteBatchNode offset + anchor + rot skew") - subtitleLabel:setString("") + Helper.titleLabel:setString("SSpriteBatchNode offset + anchor + rot skew") + Helper.subtitleLabel:setString("") return layer end @@ -1224,7 +1109,7 @@ end function SpriteTest() local scene = CCScene:create() - createFunctionTable = { + Helper.createFunctionTable = { Sprite1.create, SpriteBatchNode1.create, SpriteFrameTest.create, @@ -1242,7 +1127,7 @@ function SpriteTest() } ActionIdx = 0 - scene:addChild(nextAction()) + scene:addChild(Sprite1.create()) scene:addChild(CreateBackMenuItem()) return scene diff --git a/samples/Lua/TestLua/Resources/luaScript/helper.lua b/samples/Lua/TestLua/Resources/luaScript/helper.lua index e95796e5b9..957166bbf8 100644 --- a/samples/Lua/TestLua/Resources/luaScript/helper.lua +++ b/samples/Lua/TestLua/Resources/luaScript/helper.lua @@ -35,3 +35,73 @@ function CreateBackMenuItem() return Menu end + +Helper = { + index = 1, + createFunctioinTable = nil, + currentLayer = nil, + titleLabel = nil, + subtitleLabel = nil +} +function Helper.nextAction() + Helper.index = Helper.index + 1 + if Helper.index > table.getn(Helper.createFunctionTable) then + Helper.index = 1 + end + + return Helper.newScene() +end + +function Helper.backAction() + Helper.index = Helper.index - 1 + if Helper.index == 0 then + Helper.index = table.getn(Helper.createFunctionTable) + end + + return Helper.newScene() +end + +function Helper.restartAction() + return Helper.newScene() +end + +function Helper.newScene() + local scene = CCScene:create() + Helper.currentLayer = Helper.createFunctionTable[Helper.index]() + scene:addChild(Helper.currentLayer) + scene:addChild(CreateBackMenuItem()) + + CCDirector:sharedDirector():replaceScene(scene) +end + +function Helper.initWithLayer(layer) + local size = CCDirector:sharedDirector():getWinSize() + Helper.titleLabel = CCLabelTTF:create("", "Arial", 28) + layer:addChild(Helper.titleLabel, 1) + Helper.titleLabel:setPosition(size.width / 2, size.height - 50) + + Helper.subtitleLabel = CCLabelTTF:create("", "Thonburi", 16) + layer:addChild(Helper.subtitleLabel, 1) + Helper.subtitleLabel:setPosition(size.width / 2, size.height - 80) + + -- menu + local item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2) + local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) + local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) + item1:registerScriptTapHandler(Helper.backAction) + item2:registerScriptTapHandler(Helper.restartAction) + item3:registerScriptTapHandler(Helper.nextAction) + + local menu = CCMenu:create() + menu:addChild(item1) + menu:addChild(item2) + menu:addChild(item3) + menu:setPosition(CCPointMake(0, 0)) + item1:setPosition(CCPointMake(size.width / 2 - item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + item2:setPosition(CCPointMake(size.width / 2, item2:getContentSize().height / 2)) + item3:setPosition(CCPointMake(size.width / 2 + item2:getContentSize().width * 2, item2:getContentSize().height / 2)) + layer:addChild(menu, 1) + + local background = CCLayer:create() + layer:addChild(background, -10) +end