Merge pull request #2155 from minggo/iss1803-spritetest-lua

refactor lua test cases
This commit is contained in:
minggo 2013-03-13 02:49:46 -07:00
commit 58117a6aaf
9 changed files with 334 additions and 979 deletions

View File

@ -1,12 +1,7 @@
local SceneIdx = -1
local MAX_LAYER = 13
local kTagAction1 = 1 local kTagAction1 = 1
local kTagAction2 = 2 local kTagAction2 = 2
local kTagSlider = 1 local kTagSlider = 1
local titleLabel = nil
local s = CCDirector:sharedDirector():getWinSize() local s = CCDirector:sharedDirector():getWinSize()
local scheduler = CCDirector:sharedDirector():getScheduler() local scheduler = CCDirector:sharedDirector():getScheduler()
@ -18,53 +13,6 @@ local function createSimpleDelayTime()
return CCDelayTime:create(0.25) return CCDelayTime:create(0.25)
end 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() local function positionForTwo()
grossini:setPosition(CCPointMake(60, s.height * 1 / 5)) grossini:setPosition(CCPointMake(60, s.height * 1 / 5))
tamara:setPosition(CCPointMake(60, s.height * 4 / 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)) kathia:setPosition(CCPointMake(60, s.height * 2.5 / 5))
tamara:setPosition(CCPointMake(60, s.height * 4 / 5)) tamara:setPosition(CCPointMake(60, s.height * 4 / 5))
titleLabel = CCLabelTTF:create("", "Arial", 32) Helper.initWithLayer(layer)
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)
return layer return layer
end end
@ -175,7 +103,7 @@ local function SpriteEase()
layer:registerScriptHandler(SpriteEase_onEnterOrExit) layer:registerScriptHandler(SpriteEase_onEnterOrExit)
titleLabel:setString("EaseIn - EaseOut - Stop") Helper.titleLabel:setString("EaseIn - EaseOut - Stop")
return layer return layer
end end
@ -223,7 +151,7 @@ local function SpriteEaseInOut()
kathia:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq2))
grossini:runAction(CCRepeatForever:create(seq3)) grossini:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("EaseInOut and rates") Helper.titleLabel:setString("EaseInOut and rates")
return layer return layer
end end
@ -274,7 +202,7 @@ local function SpriteEaseExponential()
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
kathia:runAction(CCRepeatForever:create(seq3)) kathia:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("ExpIn - ExpOut actions") Helper.titleLabel:setString("ExpIn - ExpOut actions")
return layer return layer
end end
@ -314,7 +242,7 @@ local function SpriteEaseExponentialInOut()
grossini:runAction(CCRepeatForever:create(seq1)) grossini:runAction(CCRepeatForever:create(seq1))
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
titleLabel:setString("EaseExponentialInOut action") Helper.titleLabel:setString("EaseExponentialInOut action")
return layer return layer
end end
@ -360,7 +288,7 @@ local function SpriteEaseSine()
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
kathia:runAction(CCRepeatForever:create(seq3)) kathia:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("EaseSineIn - EaseSineOut") Helper.titleLabel:setString("EaseSineIn - EaseSineOut")
return layer return layer
end end
@ -397,7 +325,7 @@ local function SpriteEaseSineInOut()
grossini:runAction(CCRepeatForever:create(seq1)) grossini:runAction(CCRepeatForever:create(seq1))
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
titleLabel:setString("EaseSineInOut action") Helper.titleLabel:setString("EaseSineInOut action")
return layer return layer
end end
@ -443,7 +371,7 @@ local function SpriteEaseElastic()
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
kathia:runAction(CCRepeatForever:create(seq3)) kathia:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("Elastic In - Out actions") Helper.titleLabel:setString("Elastic In - Out actions")
return layer return layer
end end
@ -491,7 +419,7 @@ local function SpriteEaseElasticInOut()
kathia:runAction(CCRepeatForever:create(seq2)) kathia:runAction(CCRepeatForever:create(seq2))
grossini:runAction(CCRepeatForever:create(seq3)) grossini:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("EaseElasticInOut action") Helper.titleLabel:setString("EaseElasticInOut action")
return layer return layer
end end
@ -537,7 +465,7 @@ local function SpriteEaseBounce()
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
kathia:runAction(CCRepeatForever:create(seq3)) kathia:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("Bounce In - Out actions") Helper.titleLabel:setString("Bounce In - Out actions")
return layer return layer
end end
@ -574,7 +502,7 @@ local function SpriteEaseBounceInOut()
grossini:runAction(CCRepeatForever:create(seq1)) grossini:runAction(CCRepeatForever:create(seq1))
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
titleLabel:setString("EaseBounceInOut action") Helper.titleLabel:setString("EaseBounceInOut action")
return layer return layer
end end
@ -620,7 +548,7 @@ local function SpriteEaseBack()
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
kathia:runAction(CCRepeatForever:create(seq3)) kathia:runAction(CCRepeatForever:create(seq3))
titleLabel:setString("Back In - Out actions") Helper.titleLabel:setString("Back In - Out actions")
return layer return layer
end end
@ -657,7 +585,7 @@ local function SpriteEaseBackInOut()
grossini:runAction(CCRepeatForever:create(seq1)) grossini:runAction(CCRepeatForever:create(seq1))
tamara:runAction(CCRepeatForever:create(seq2)) tamara:runAction(CCRepeatForever:create(seq2))
titleLabel:setString("EaseBackInOut action") Helper.titleLabel:setString("EaseBackInOut action")
return layer return layer
end end
@ -709,48 +637,31 @@ local function SpeedTest()
layer:registerScriptHandler(SpeedTest_onEnterOrExit) layer:registerScriptHandler(SpeedTest_onEnterOrExit)
titleLabel:setString("Speed action") Helper.titleLabel:setString("Speed action")
return layer return layer
end 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() function EaseActionsTest()
local scene = CCScene:create() local scene = CCScene:create()
cclog("EaseActionsTest")
SceneIdx = -1 Helper.createFunctionTable = {
scene:addChild(nextAction()) SpriteEase,
SpriteEaseInOut,
SpriteEaseExponential,
SpriteEaseExponentialInOut,
SpriteEaseSine,
SpriteEaseSineInOut,
SpriteEaseElastic,
SpriteEaseElasticInOut,
SpriteEaseBounce,
SpriteEaseBounceInOut,
SpriteEaseBack,
SpriteEaseBackInOut,
SpeedTest
}
scene:addChild(SpriteEase())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -1,90 +1,12 @@
local SceneIdx = -1
local MAX_LAYER = 7
local s = CCDirector:sharedDirector():getWinSize() 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 -- SpriteProgressToRadial
------------------------------------ ------------------------------------
local function SpriteProgressToRadial() local function SpriteProgressToRadial()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to1 = CCProgressTo:create(2, 100) local to1 = CCProgressTo:create(2, 100)
local to2 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100)
@ -103,7 +25,7 @@ local function SpriteProgressToRadial()
right:runAction(CCRepeatForever:create(to2)) right:runAction(CCRepeatForever:create(to2))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("ProgressTo Radial") Helper.subtitleLabel:setString("ProgressTo Radial")
return layer return layer
end end
@ -112,7 +34,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressToHorizontal() local function SpriteProgressToHorizontal()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to1 = CCProgressTo:create(2, 100) local to1 = CCProgressTo:create(2, 100)
local to2 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100)
@ -137,7 +59,7 @@ local function SpriteProgressToHorizontal()
right:runAction(CCRepeatForever:create(to2)) right:runAction(CCRepeatForever:create(to2))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("ProgressTo Horizontal") Helper.subtitleLabel:setString("ProgressTo Horizontal")
return layer return layer
end end
@ -146,7 +68,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressToVertical() local function SpriteProgressToVertical()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to1 = CCProgressTo:create(2, 100) local to1 = CCProgressTo:create(2, 100)
local to2 = CCProgressTo:create(2, 100) local to2 = CCProgressTo:create(2, 100)
@ -172,7 +94,7 @@ local function SpriteProgressToVertical()
right:runAction(CCRepeatForever:create(to2)) right:runAction(CCRepeatForever:create(to2))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("ProgressTo Vertical") Helper.subtitleLabel:setString("ProgressTo Vertical")
return layer return layer
end end
@ -181,7 +103,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressToRadialMidpointChanged() local function SpriteProgressToRadialMidpointChanged()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local action = CCProgressTo:create(2, 100) local action = CCProgressTo:create(2, 100)
@ -206,7 +128,7 @@ local function SpriteProgressToRadialMidpointChanged()
right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100))) right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100)))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("Radial w/ Different Midpoints") Helper.subtitleLabel:setString("Radial w/ Different Midpoints")
return layer return layer
end end
@ -215,7 +137,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressBarVarious() local function SpriteProgressBarVarious()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to = CCProgressTo:create(2, 100) local to = CCProgressTo:create(2, 100)
@ -250,7 +172,7 @@ local function SpriteProgressBarVarious()
right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100))) right:runAction(CCRepeatForever:create(CCProgressTo:create(2, 100)))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("ProgressTo Bar Mid") Helper.subtitleLabel:setString("ProgressTo Bar Mid")
return layer return layer
end end
@ -259,7 +181,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressBarTintAndFade() local function SpriteProgressBarTintAndFade()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to = CCProgressTo:create(6, 100) local to = CCProgressTo:create(6, 100)
local array = CCArray:create() local array = CCArray:create()
@ -318,7 +240,7 @@ local function SpriteProgressBarTintAndFade()
right:addChild(CCLabelTTF:create("Tint and Fade", "Marker Felt", 20.0)) right:addChild(CCLabelTTF:create("Tint and Fade", "Marker Felt", 20.0))
subtitleLabel:setString("ProgressTo Bar Mid") Helper.subtitleLabel:setString("ProgressTo Bar Mid")
return layer return layer
end end
@ -327,7 +249,7 @@ end
------------------------------------ ------------------------------------
local function SpriteProgressWithSpriteFrame() local function SpriteProgressWithSpriteFrame()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local to = CCProgressTo:create(6, 100) local to = CCProgressTo:create(6, 100)
@ -363,41 +285,24 @@ local function SpriteProgressWithSpriteFrame()
right:runAction(CCRepeatForever:create(CCProgressTo:create(6, 100))) right:runAction(CCRepeatForever:create(CCProgressTo:create(6, 100)))
layer:addChild(right) layer:addChild(right)
subtitleLabel:setString("Progress With Sprite Frame") Helper.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
return layer return layer
end end
function ProgressActionsTest() function ProgressActionsTest()
cclog("ProgressActionsTest")
local scene = CCScene:create() local scene = CCScene:create()
SceneIdx = -1 Helper.createFunctionTable = {
scene:addChild(nextAction()) SpriteProgressToRadial,
SpriteProgressToHorizontal,
SpriteProgressToVertical,
SpriteProgressToRadialMidpointChanged,
SpriteProgressBarVarious,
SpriteProgressBarTintAndFade,
SpriteProgressWithSpriteFrame
}
scene:addChild(SpriteProgressToRadial())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
CCDirector:sharedDirector():replaceScene(scene) CCDirector:sharedDirector():replaceScene(scene)

View File

@ -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)

View File

@ -1,59 +1,8 @@
require "luaScript/ActionsTest/ActionsName" require "luaScript/ActionsTest/ActionsName"
local ActionIdx = -1
local size = CCDirector:sharedDirector():getWinSize() 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) local function initWithLayer(layer)
grossini = CCSprite:create(s_pPathGrossini) grossini = CCSprite:create(s_pPathGrossini)
tamara = CCSprite:create(s_pPathSister1) tamara = CCSprite:create(s_pPathSister1)
@ -67,31 +16,7 @@ local function initWithLayer(layer)
tamara:setPosition(ccp(size.width / 2, 2 * size.height / 3)) tamara:setPosition(ccp(size.width / 2, 2 * size.height / 3))
kathia:setPosition(ccp(size.width / 2, size.height / 2)) kathia:setPosition(ccp(size.width / 2, size.height / 2))
-- create title and subtitle Helper.initWithLayer(layer)
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)
end end
@ -151,7 +76,7 @@ local function ActionManual()
kathia:setPosition(ccp(size.width - 100, size.height / 2)) kathia:setPosition(ccp(size.width - 100, size.height / 2))
kathia:setColor(ccc3(0, 0, 255)) kathia:setColor(ccc3(0, 0, 255))
subtitleLabel:setString("Manual Transformation") Helper.subtitleLabel:setString("Manual Transformation")
return layer return layer
end end
@ -170,7 +95,7 @@ local function ActionMove()
grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack))
kathia:runAction(CCMoveTo:create(1, ccp(40, 40))) kathia:runAction(CCMoveTo:create(1, ccp(40, 40)))
subtitleLabel:setString("MoveTo / MoveBy") Helper.subtitleLabel:setString("MoveTo / MoveBy")
return layer return layer
end end
@ -191,7 +116,7 @@ local function ActionScale()
tamara:runAction(CCSequence:createWithTwoActions(actionBy, actionBy:reverse())) tamara:runAction(CCSequence:createWithTwoActions(actionBy, actionBy:reverse()))
kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse())) kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse()))
subtitleLabel:setString("ScaleTo / ScaleBy") Helper.subtitleLabel:setString("ScaleTo / ScaleBy")
return layer return layer
end end
@ -217,7 +142,7 @@ local function ActionRotate()
kathia:runAction(CCSequence:createWithTwoActions(actionTo2, action0Retain)) kathia:runAction(CCSequence:createWithTwoActions(actionTo2, action0Retain))
subtitleLabel:setString("RotateTo / RotateBy") Helper.subtitleLabel:setString("RotateTo / RotateBy")
return layer return layer
end end
@ -240,7 +165,7 @@ local function ActionSkew()
grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack))
kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse())) kathia:runAction(CCSequence:createWithTwoActions(actionBy2, actionBy2:reverse()))
subtitleLabel:setString("SkewTo / SkewBy") Helper.subtitleLabel:setString("SkewTo / SkewBy")
return layer return layer
end end
@ -285,7 +210,7 @@ local function ActionRotationalSkewVSStandardSkew()
seq = CCSequence:createWithTwoActions(actionTo2, actionToBack2) seq = CCSequence:createWithTwoActions(actionTo2, actionToBack2)
box:runAction(seq); box:runAction(seq);
subtitleLabel:setString("Skew Comparison") Helper.subtitleLabel:setString("Skew Comparison")
return layer; return layer;
end end
@ -333,7 +258,7 @@ local function ActionSkewRotate()
box:runAction(CCSequence:createWithTwoActions(rotateTo, rotateToBack)) box:runAction(CCSequence:createWithTwoActions(rotateTo, rotateToBack))
box:runAction(CCSequence:createWithTwoActions(actionScaleTo, actionScaleToBack)) box:runAction(CCSequence:createWithTwoActions(actionScaleTo, actionScaleToBack))
subtitleLabel:setString("Skew + Rotate + Scale") Helper.subtitleLabel:setString("Skew + Rotate + Scale")
return layer return layer
end end
@ -355,7 +280,7 @@ local function ActionJump()
grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack)) grossini:runAction(CCSequence:createWithTwoActions(actionBy, actionByBack))
kathia:runAction(CCRepeatForever:create(actionUp)) kathia:runAction(CCRepeatForever:create(actionUp))
subtitleLabel:setString("JumpTo / JumpBy") Helper.subtitleLabel:setString("JumpTo / JumpBy")
return layer return layer
end end
@ -403,8 +328,8 @@ local function ActionCardinalSpline()
drawCardinalSpline(array) drawCardinalSpline(array)
titleLabel:setString("CardinalSplineBy / CardinalSplineAt") Helper.titleLabel:setString("CardinalSplineBy / CardinalSplineAt")
subtitleLabel:setString("Cardinal Spline paths.\nTesting different tensions for one array") Helper.subtitleLabel:setString("Cardinal Spline paths.\nTesting different tensions for one array")
return layer return layer
end end
@ -456,8 +381,8 @@ local function ActionCatmullRom()
drawCatmullRom(array, array2) drawCatmullRom(array, array2)
titleLabel:setString("CatmullRomBy / CatmullRomTo") Helper.titleLabel:setString("CatmullRomBy / CatmullRomTo")
subtitleLabel:setString("Catmull Rom spline paths. Testing reverse too") Helper.subtitleLabel:setString("Catmull Rom spline paths. Testing reverse too")
return layer return layer
end end
@ -497,7 +422,7 @@ local function ActionBezier()
tamara:runAction(bezierTo1) tamara:runAction(bezierTo1)
kathia:runAction(bezierTo2) kathia:runAction(bezierTo2)
subtitleLabel:setString("BezierTo / BezierBy") Helper.subtitleLabel:setString("BezierTo / BezierBy")
return layer return layer
end end
@ -516,7 +441,7 @@ local function ActionBlink()
tamara:runAction(action1) tamara:runAction(action1)
kathia:runAction(action2) kathia:runAction(action2)
subtitleLabel:setString("Blink") Helper.subtitleLabel:setString("Blink")
return layer return layer
end end
@ -540,7 +465,7 @@ local function ActionFade()
tamara:runAction(CCSequence:createWithTwoActions( action1, action1Back)) tamara:runAction(CCSequence:createWithTwoActions( action1, action1Back))
kathia:runAction(CCSequence:createWithTwoActions( action2, action2Back)) kathia:runAction(CCSequence:createWithTwoActions( action2, action2Back))
subtitleLabel:setString("FadeIn / FadeOut") Helper.subtitleLabel:setString("FadeIn / FadeOut")
return layer return layer
end end
@ -561,7 +486,7 @@ local function ActionTint()
tamara:runAction(action1) tamara:runAction(action1)
kathia:runAction(CCSequence:createWithTwoActions(action2, action2Back)) kathia:runAction(CCSequence:createWithTwoActions(action2, action2Back))
subtitleLabel:setString("TintTo / TintBy") Helper.subtitleLabel:setString("TintTo / TintBy")
return layer return layer
end end
@ -607,8 +532,8 @@ local function ActionAnimate()
local action3 = CCAnimate:create(animation3) local action3 = CCAnimate:create(animation3)
kathia:runAction(action3) kathia:runAction(action3)
titleLabel:setString("Animation") Helper.titleLabel:setString("Animation")
subtitleLabel:setString("Center: Manual animation. Border: using file format animation") Helper.subtitleLabel:setString("Center: Manual animation. Border: using file format animation")
return layer return layer
end end
@ -628,7 +553,7 @@ local function ActionSequence()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("Sequence: Move + Rotate") Helper.subtitleLabel:setString("Sequence: Move + Rotate")
return layer return layer
end end
@ -677,7 +602,7 @@ local function ActionSequence2()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("Sequence of InstantActions") Helper.subtitleLabel:setString("Sequence of InstantActions")
return actionSequenceLayer return actionSequenceLayer
end end
@ -696,7 +621,7 @@ local function ActionSpawn()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("Spawn: Jump + Rotate") Helper.subtitleLabel:setString("Spawn: Jump + Rotate")
return layer return layer
end end
@ -715,7 +640,7 @@ local function ActionReverse()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("Reverse an action") Helper.subtitleLabel:setString("Reverse an action")
return layer return layer
end end
@ -738,7 +663,7 @@ local function ActionDelaytime()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("DelayTime: m + delay + m") Helper.subtitleLabel:setString("DelayTime: m + delay + m")
return layer return layer
end end
@ -760,7 +685,7 @@ local function ActionRepeat()
kathia:runAction(action1) kathia:runAction(action1)
tamara:runAction(action2) tamara:runAction(action2)
subtitleLabel:setString("Repeat / RepeatForever actions") Helper.subtitleLabel:setString("Repeat / RepeatForever actions")
return layer return layer
end end
@ -785,7 +710,7 @@ local function ActionRepeatForever()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("CallFuncN + RepeatForever") Helper.subtitleLabel:setString("CallFuncN + RepeatForever")
return layer return layer
end end
@ -807,7 +732,7 @@ local function ActionRotateToRepeat()
tamara:runAction(rep1) tamara:runAction(rep1)
kathia:runAction(rep2) kathia:runAction(rep2)
subtitleLabel:setString("Repeat/RepeatForever + RotateTo") Helper.subtitleLabel:setString("Repeat/RepeatForever + RotateTo")
return layer return layer
end end
@ -836,7 +761,7 @@ local function ActionRotateJerk()
tamara:runAction(rep1) tamara:runAction(rep1)
kathia:runAction(rep2) kathia:runAction(rep2)
subtitleLabel:setString("RepeatForever / Repeat + Rotate") Helper.subtitleLabel:setString("RepeatForever / Repeat + Rotate")
return layer return layer
end end
@ -892,7 +817,7 @@ local function ActionCallFunc()
tamara:runAction(action2) tamara:runAction(action2)
kathia:runAction(action3) kathia:runAction(action3)
subtitleLabel:setString("Callbacks: CallFunc and friends") Helper.subtitleLabel:setString("Callbacks: CallFunc and friends")
return callFuncLayer return callFuncLayer
end end
@ -908,8 +833,8 @@ local function ActionCallFuncND()
centerSprites(1) centerSprites(1)
titleLabel:setString("CallFuncND + auto remove") Helper.titleLabel:setString("CallFuncND + auto remove")
subtitleLabel:setString("CallFuncND + removeFromParentAndCleanup. Grossini dissapears in 2s") Helper.subtitleLabel:setString("CallFuncND + removeFromParentAndCleanup. Grossini dissapears in 2s")
return layer return layer
end end
@ -933,7 +858,7 @@ local function ActionReverseSequence()
grossini:runAction(action) grossini:runAction(action)
subtitleLabel:setString("Reverse a sequence") Helper.subtitleLabel:setString("Reverse a sequence")
return layer return layer
end end
@ -976,7 +901,7 @@ local function ActionReverseSequence2()
local seq_back = seq_tamara:reverse() local seq_back = seq_tamara:reverse()
tamara:runAction(CCSequence:createWithTwoActions(seq_tamara, seq_back)) tamara:runAction(CCSequence:createWithTwoActions(seq_tamara, seq_back))
subtitleLabel:setString("Reverse a sequence2") Helper.subtitleLabel:setString("Reverse a sequence2")
return layer return layer
end end
@ -1011,7 +936,7 @@ local function ActionOrbit()
grossini:runAction(tolua.cast(rfe:copy():autorelease(), "CCActionInterval")) grossini:runAction(tolua.cast(rfe:copy():autorelease(), "CCActionInterval"))
subtitleLabel:setString("OrbitCamera action") Helper.subtitleLabel:setString("OrbitCamera action")
return layer return layer
end end
@ -1034,7 +959,7 @@ local function ActionFollow()
layer:runAction(CCFollow:create(grossini, CCRectMake(0, 0, size.width * 2 - 100, size.height))) 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 return layer
end end
@ -1065,8 +990,8 @@ local function ActionTargeted()
tamara:runAction(always) tamara:runAction(always)
titleLabel:setString("ActionTargeted") Helper.titleLabel:setString("ActionTargeted")
subtitleLabel:setString("Action that runs on another target. Useful for sequences") Helper.subtitleLabel:setString("Action that runs on another target. Useful for sequences")
return layer return layer
end end
@ -1125,8 +1050,8 @@ local function PauseResumeActions()
layer:registerScriptHandler(PauseResumeActions_onEnterOrExit) layer:registerScriptHandler(PauseResumeActions_onEnterOrExit)
titleLabel:setString("PauseResumeActions") Helper.titleLabel:setString("PauseResumeActions")
subtitleLabel:setString("All actions pause at 3s and resume at 5s") Helper.subtitleLabel:setString("All actions pause at 3s and resume at 5s")
return layer return layer
end end
@ -1169,8 +1094,8 @@ local function ActionIssue1305()
Issue1305_layer:registerScriptHandler(Issue1305_onEnterOrExit) Issue1305_layer:registerScriptHandler(Issue1305_onEnterOrExit)
titleLabel:setString("Issue 1305") Helper.titleLabel:setString("Issue 1305")
subtitleLabel:setString("In two seconds you should see a message on the console. NOT BEFORE.") Helper.subtitleLabel:setString("In two seconds you should see a message on the console. NOT BEFORE.")
return Issue1305_layer return Issue1305_layer
end end
@ -1225,8 +1150,8 @@ local function ActionIssue1305_2()
CCDirector:sharedDirector():getActionManager():addAction(actF ,spr, false) CCDirector:sharedDirector():getActionManager():addAction(actF ,spr, false)
titleLabel:setString("Issue 1305 #2") Helper.titleLabel:setString("Issue 1305 #2")
subtitleLabel:setString("See console. You should only see one message for each block") Helper.subtitleLabel:setString("See console. You should only see one message for each block")
return layer return layer
end end
@ -1250,8 +1175,8 @@ local function ActionIssue1288()
spr:runAction(act4) spr:runAction(act4)
titleLabel:setString("Issue 1288") Helper.titleLabel:setString("Issue 1288")
subtitleLabel:setString("Sprite should end at the position where it started.") Helper.subtitleLabel:setString("Sprite should end at the position where it started.")
return layer return layer
end end
@ -1271,8 +1196,8 @@ local function ActionIssue1288_2()
local act1 = CCMoveBy:create(0.5, ccp(100, 0)) local act1 = CCMoveBy:create(0.5, ccp(100, 0))
spr:runAction(CCRepeat:create(act1, 1)) spr:runAction(CCRepeat:create(act1, 1))
titleLabel:setString("Issue 1288 #2") Helper.titleLabel:setString("Issue 1288 #2")
subtitleLabel:setString("Sprite should move 100 pixels, and stay there") Helper.subtitleLabel:setString("Sprite should move 100 pixels, and stay there")
return layer return layer
end end
@ -1315,92 +1240,8 @@ local function ActionIssue1327()
array:addObject(act9) array:addObject(act9)
spr:runAction(CCSequence:create(array)) spr:runAction(CCSequence:create(array))
titleLabel:setString("Issue 1327") Helper.titleLabel:setString("Issue 1327")
subtitleLabel:setString("See console: You should see: 0, 45, 90, 135, 180") Helper.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
return layer return layer
end end
@ -1408,8 +1249,47 @@ function ActionsTest()
cclog("ActionsTest") cclog("ActionsTest")
local scene = CCScene:create() local scene = CCScene:create()
ActionIdx = -1 Helper.createFunctionTable = {
scene:addChild(NextAction()) 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()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -5,73 +5,13 @@ local MAX_LAYER = 2
local background = nil local background = nil
local labelAtlas = nil local labelAtlas = nil
local titleLabel = nil
local subtitleLabel = nil
local baseLayer_entry = nil local baseLayer_entry = nil
local s = CCDirector:sharedDirector():getWinSize() 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 function getBaseLayer()
local layer = CCLayer:create() 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 item1 = CCMenuItemImage:create(s_pPathB1, s_pPathB2)
local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2) local item2 = CCMenuItemImage:create(s_pPathR1, s_pPathR2)
local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2) local item3 = CCMenuItemImage:create(s_pPathF1, s_pPathF2)
@ -82,27 +22,14 @@ local function getBaseLayer()
item2:registerScriptTapHandler(restartCallback) item2:registerScriptTapHandler(restartCallback)
item3:registerScriptTapHandler(nextCallback) 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('.')) labelAtlas = CCLabelAtlas:create("0000", "fps_images.png", 12, 32, string.byte('.'))
layer:addChild(labelAtlas, 100) layer:addChild(labelAtlas, 100)
labelAtlas:setPosition(ccp(s.width - 66, 50)) labelAtlas:setPosition(ccp(s.width - 66, 50))
layer:setTouchEnabled(false) layer:setTouchEnabled(false)
Helper.initWithLayer(layer)
return layer return layer
end end
@ -199,8 +126,11 @@ function DrawPrimitivesTest()
cclog("DrawPrimitivesTest") cclog("DrawPrimitivesTest")
local scene = CCScene:create() local scene = CCScene:create()
SceneIdx = -1 Helper.createFunctionTable = {
scene:addChild(nextAction()) drawPrimitivesTest
}
scene:addChild(drawPrimitivesTest())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -1,7 +1,4 @@
local SceneIdx = 0
local MAX_LAYER = 3
local streak = nil local streak = nil
local titleLabel = nil local titleLabel = nil
local subtitleLabel = nil local subtitleLabel = nil
@ -11,26 +8,6 @@ local scheduler = CCDirector:sharedDirector():getScheduler()
local firstTick = nil 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) local function modeCallback(sender)
fastMode = streak:isFastMode() fastMode = streak:isFastMode()
if fastMode == true then if fastMode == true then
@ -40,62 +17,9 @@ local function modeCallback(sender)
end end
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 function getBaseLayer()
local layer = CCLayer:create() 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")) local itemMode = CCMenuItemToggle:create(CCMenuItemFont:create("Use High Quality Mode"))
itemMode:addSubItem(CCMenuItemFont:create("Use Fast Mode")) itemMode:addSubItem(CCMenuItemFont:create("Use Fast Mode"))
itemMode:registerScriptTapHandler(modeCallback) itemMode:registerScriptTapHandler(modeCallback)
@ -104,6 +28,8 @@ local function getBaseLayer()
menuMode:setPosition(ccp(s.width / 2, s.height / 4)) menuMode:setPosition(ccp(s.width / 2, s.height / 4))
layer:addChild(menuMode) layer:addChild(menuMode)
Helper.initWithLayer(layer)
return layer return layer
end end
@ -167,7 +93,7 @@ local function MotionStreakTest1()
firstTick = true firstTick = true
layer:registerScriptHandler(MotionStreakTest1_onEnterOrExit) layer:registerScriptHandler(MotionStreakTest1_onEnterOrExit)
titleLabel:setString("MotionStreak test 1") Helper.titleLabel:setString("MotionStreak test 1")
return layer return layer
end end
@ -203,7 +129,7 @@ local function MotionStreakTest2()
layer:setTouchEnabled(true) layer:setTouchEnabled(true)
layer:registerScriptTouchHandler(onTouch) layer:registerScriptTouchHandler(onTouch)
titleLabel:setString("MotionStreak test") Helper.titleLabel:setString("MotionStreak test")
return layer return layer
end end
@ -247,29 +173,21 @@ local function Issue1358()
firstTick = true firstTick = true
layer:registerScriptHandler(Issue1358_onEnterOrExit) layer:registerScriptHandler(Issue1358_onEnterOrExit)
titleLabel:setString("Issue 1358") Helper.titleLabel:setString("Issue 1358")
subtitleLabel:setString("The tail should use the texture") Helper.subtitleLabel:setString("The tail should use the texture")
return layer return layer
end 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() function MotionStreakTest()
local scene = CCScene:create() local scene = CCScene:create()
SceneIdx = -1 Helper.createFunctionTable = {
scene:addChild(nextAction()) MotionStreakTest1,
MotionStreakTest2,
Issue1358
}
scene:addChild(MotionStreakTest1())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -1,94 +1,17 @@
local SceneIdx = -1
local MAX_LAYER = 13
local kTagSprite1 = 1 local kTagSprite1 = 1
local kTagSprite2 = 2 local kTagSprite2 = 2
local kTagSprite3 = 3 local kTagSprite3 = 3
local kTagSlider = 4 local kTagSlider = 4
local titleLabel = nil
local subTitleLabel = nil
local s = CCDirector:sharedDirector():getWinSize() local s = CCDirector:sharedDirector():getWinSize()
local scheduler = CCDirector:sharedDirector():getScheduler() 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 function getBaseLayer()
local layer = CCLayer:create() local layer = CCLayer:create()
titleLabel = CCLabelTTF:create("", "Arial", 32) Helper.initWithLayer(layer)
layer:addChild(titleLabel, 10)
titleLabel:setPosition(s.width / 2, s.height - 50)
subTitleLabel = CCLabelTTF:create("", "Thonburi", 16) return layer
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
end end
----------------------------------- -----------------------------------
@ -143,8 +66,8 @@ local function CameraCenterTest()
orbit = CCOrbitCamera:create(10, 1, 0, 0, 360, 0, 0) orbit = CCOrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(CCRepeatForever:create(orbit)) sprite:runAction(CCRepeatForever:create(orbit))
titleLabel:setString("Camera Center test") Helper.titleLabel:setString("Camera Center test")
subTitleLabel:setString("Sprites should rotate at the same speed") Helper.subtitleLabel:setString("Sprites should rotate at the same speed")
return layer return layer
end end
@ -189,7 +112,7 @@ local function Test2()
sp1:runAction(action1) sp1:runAction(action1)
sp2:runAction(action2) sp2:runAction(action2)
titleLabel:setString("anchorPoint and children") Helper.titleLabel:setString("anchorPoint and children")
return layer return layer
end end
@ -234,7 +157,7 @@ local function Test4()
Test4_layer:registerScriptHandler(Test4_onEnterOrExit) Test4_layer:registerScriptHandler(Test4_onEnterOrExit)
titleLabel:setString("tags") Helper.titleLabel:setString("tags")
return Test4_layer return Test4_layer
end end
@ -297,7 +220,7 @@ local function Test5()
Test5_layer:registerScriptHandler(Test5_onEnterOrExit) Test5_layer:registerScriptHandler(Test5_onEnterOrExit)
titleLabel:setString("remove and cleanup") Helper.titleLabel:setString("remove and cleanup")
return Test5_layer return Test5_layer
end end
@ -364,7 +287,7 @@ local function Test6()
Test6_layer:registerScriptHandler(Test6_onEnterOrExit) Test6_layer:registerScriptHandler(Test6_onEnterOrExit)
titleLabel:setString("remove/cleanup with children") Helper.titleLabel:setString("remove/cleanup with children")
return Test6_layer return Test6_layer
end end
@ -377,7 +300,7 @@ local StressTest1_layer = nil
local function removeMe(node) local function removeMe(node)
local parent = StressTest1_layer:getParent() local parent = StressTest1_layer:getParent()
parent:removeChild(node, true) parent:removeChild(node, true)
nextCallback(node) Helper.nextAction()
end end
local function shouldNotCrash(dt) local function shouldNotCrash(dt)
@ -413,7 +336,7 @@ local function StressTest1()
StressTest1_layer:registerScriptHandler(StressTest1_onEnterOrExit) StressTest1_layer:registerScriptHandler(StressTest1_onEnterOrExit)
titleLabel:setString("stress test #1: no crashes") Helper.titleLabel:setString("stress test #1: no crashes")
return StressTest1_layer return StressTest1_layer
end end
@ -466,7 +389,7 @@ local function StressTest2()
StressTest2_layer:addChild(sublayer, 0, kTagSprite1) StressTest2_layer:addChild(sublayer, 0, kTagSprite1)
titleLabel:setString("stress test #2: no leaks") Helper.titleLabel:setString("stress test #2: no leaks")
return StressTest2_layer return StressTest2_layer
end end
@ -502,7 +425,7 @@ local function NodeToWorld()
local fe2 = CCRepeatForever:create(seq) local fe2 = CCRepeatForever:create(seq)
back:runAction(fe2) back:runAction(fe2)
titleLabel:setString("nodeToParent transform") Helper.titleLabel:setString("nodeToParent transform")
return layer return layer
end end
@ -558,7 +481,7 @@ local function CameraOrbitTest()
layer:setScale(1) layer:setScale(1)
titleLabel:setString("Camera Orbit test") Helper.titleLabel:setString("Camera Orbit test")
return layer return layer
end end
@ -617,7 +540,7 @@ local function CameraZoomTest()
CameraZoomTest_layer:scheduleUpdateWithPriorityLua(CameraZoomTest_update, 0) CameraZoomTest_layer:scheduleUpdateWithPriorityLua(CameraZoomTest_update, 0)
CameraZoomTest_layer:registerScriptHandler(CameraZoomTest_onEnterOrExit) CameraZoomTest_layer:registerScriptHandler(CameraZoomTest_onEnterOrExit)
titleLabel:setString("Camera Zoom test") Helper.titleLabel:setString("Camera Zoom test")
return CameraZoomTest_layer return CameraZoomTest_layer
end end
@ -677,8 +600,8 @@ local function ConvertToNode()
ConvertToNode_layer:setTouchEnabled(true) ConvertToNode_layer:setTouchEnabled(true)
ConvertToNode_layer:registerScriptTouchHandler(onTouch) ConvertToNode_layer:registerScriptTouchHandler(onTouch)
titleLabel:setString("Convert To Node Space") Helper.titleLabel:setString("Convert To Node Space")
subTitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console") Helper.subtitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console")
return ConvertToNode_layer return ConvertToNode_layer
end end
@ -698,8 +621,8 @@ local function NodeOpaqueTest()
layer:addChild(background) layer:addChild(background)
end end
titleLabel:setString("Node Opaque Test") Helper.titleLabel:setString("Node Opaque Test")
subTitleLabel:setString("Node rendered with GL_BLEND disabled") Helper.subtitleLabel:setString("Node rendered with GL_BLEND disabled")
return layer return layer
end end
@ -718,50 +641,31 @@ local function NodeNonOpaqueTest()
background:setAnchorPoint(ccp(0, 0)) background:setAnchorPoint(ccp(0, 0))
layer:addChild(background) layer:addChild(background)
end end
titleLabel:setString("Node Non Opaque Test") Helper.titleLabel:setString("Node Non Opaque Test")
subTitleLabel:setString("Node rendered with GL_BLEND enabled") Helper.subtitleLabel:setString("Node rendered with GL_BLEND enabled")
return layer return layer
end 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() function CocosNodeTest()
cclog("NodeTest")
local scene = CCScene:create() local scene = CCScene:create()
SceneIdx = -1 Helper.createFunctionTable = {
scene:addChild(nextAction()) CameraCenterTest,
Test2,
Test4,
Test5,
Test6,
StressTest1,
StressTest2,
NodeToWorld,
CameraOrbitTest,
CameraZoomTest,
ConvertToNode,
NodeOpaqueTest,
NodeNonOpaqueTest
}
scene:addChild(CameraCenterTest())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -1,9 +1,4 @@
local ActionIdx = 0
local createFunctionTable = nil
local size = CCDirector:sharedDirector():getWinSize() local size = CCDirector:sharedDirector():getWinSize()
local kTagTileMap = 1 local kTagTileMap = 1
local kTagSpriteBatchNode = 1 local kTagSpriteBatchNode = 1
local kTagNode = 2 local kTagNode = 2
@ -21,108 +16,7 @@ local kTagSprite7 = 6
local kTagSprite8 = 7 local kTagSprite8 = 7
local testLayer = nil local testLayer = nil
local titleLabel = nil
local entry = 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 ---- test sprite1
@ -165,7 +59,7 @@ function Sprite1.onTouch(event, x, y)
if event == "began" then if event == "began" then
return true return true
elseif event == "ended" then elseif event == "ended" then
Sprite1.addNewSpriteWithCoords(playerLayer, ccp(x,y)) Sprite1.addNewSpriteWithCoords(Helper.currentLayer, ccp(x,y))
return true return true
end end
end end
@ -173,12 +67,12 @@ end
function Sprite1.create() function Sprite1.create()
cclog("sprite1") cclog("sprite1")
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
Sprite1.addNewSpriteWithCoords(layer, ccp(size.width/2, size.height/2)) Sprite1.addNewSpriteWithCoords(layer, ccp(size.width/2, size.height/2))
layer:setTouchEnabled(true) layer:setTouchEnabled(true)
layer:registerScriptTouchHandler(Sprite1.onTouch) layer:registerScriptTouchHandler(Sprite1.onTouch)
titleLabel:setString("Sprite (tap screen)") Helper.titleLabel:setString("Sprite (tap screen)")
return layer return layer
end end
@ -225,14 +119,14 @@ function SpriteBatchNode1.onTouch(event, x, y)
if event == "began" then if event == "began" then
return true return true
elseif event == "ended" then elseif event == "ended" then
SpriteBatchNode1.addNewSpriteWithCoords(playerLayer, ccp(x,y)) SpriteBatchNode1.addNewSpriteWithCoords(Helper.currentLayer, ccp(x,y))
return true return true
end end
end end
function SpriteBatchNode1.create() function SpriteBatchNode1.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
local BatchNode = CCSpriteBatchNode:create("Images/grossini_dance_atlas.png", 50) local BatchNode = CCSpriteBatchNode:create("Images/grossini_dance_atlas.png", 50)
layer:addChild(BatchNode, 0, kTagSpriteBatchNode) layer:addChild(BatchNode, 0, kTagSpriteBatchNode)
@ -241,7 +135,7 @@ function SpriteBatchNode1.create()
layer:setTouchEnabled(true) layer:setTouchEnabled(true)
layer:registerScriptTouchHandler(SpriteBatchNode1.onTouch) layer:registerScriptTouchHandler(SpriteBatchNode1.onTouch)
titleLabel:setString("SpriteBatchNode (tap screen)") Helper.titleLabel:setString("SpriteBatchNode (tap screen)")
return layer return layer
end end
@ -308,29 +202,29 @@ function SpriteColorOpacity.setLayerSprite(layer)
end end
function SpriteColorOpacity.onEnterOrExit(tag) function SpriteColorOpacity.onEnterOrExit(tag)
local schedule = CCDirector:sharedDirector():getScheduler()
if tag == "enter" then if tag == "enter" then
SpriteColorOpacity.entry = scheduler:scheduleScriptFunc(SpriteColorOpacity.removeAndAddSprite, 0, false) SpriteColorOpacity.onEnter()
elseif tag == "exit" then elseif tag == "exit" then
scheduler:unscheduleScriptEntry(SpriteColorOpacity.entry) SpriteColorOpacity.onExit()
end end
end end
function SpriteColorOpacity.removeAndAddSprite(dt) function SpriteColorOpacity.removeAndAddSprite(dt)
local sprite = playerLayer:getChildByTag(kTagSprite5) local sprite = Helper.currentLayer:getChildByTag(kTagSprite5)
sprite:retain() sprite:retain()
playerLayer:removeChild(sprite, false) Helper.currentLayer:removeChild(sprite, false)
playerLayer:addChild(sprite, 0, kTagSprite5) Helper.currentLayer:addChild(sprite, 0, kTagSprite5)
sprite:release() sprite:release()
end end
function SpriteColorOpacity.create() function SpriteColorOpacity.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
SpriteColorOpacity.setLayerSprite(layer) SpriteColorOpacity.setLayerSprite(layer)
titleLabel:setString("Sprite: Color & Opacity") layer:registerScriptHandler(SpriteColorOpacity.onEnterOrExit)
Helper.titleLabel:setString("Sprite: Color & Opacity")
return layer return layer
end end
@ -358,7 +252,7 @@ function SpriteFrameTest.onEnter()
local spritebatch = CCSpriteBatchNode:create("animations/grossini.png") local spritebatch = CCSpriteBatchNode:create("animations/grossini.png")
spritebatch:addChild(SpriteFrameTest.m_pSprite1) spritebatch:addChild(SpriteFrameTest.m_pSprite1)
playerLayer:addChild(spritebatch) Helper.currentLayer:addChild(spritebatch)
local animFrames = CCArray:createWithCapacity(15) local animFrames = CCArray:createWithCapacity(15)
for i = 1,14 do for i = 1,14 do
@ -374,7 +268,7 @@ function SpriteFrameTest.onEnter()
SpriteFrameTest.m_pSprite2 = CCSprite:createWithSpriteFrameName("grossini_dance_01.png") SpriteFrameTest.m_pSprite2 = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
SpriteFrameTest.m_pSprite2:setPosition( ccp( s.width/2 + 80, s.height/2) ) 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) local moreFrames = CCArray:createWithCapacity(20)
for i = 1,14 do for i = 1,14 do
@ -396,12 +290,8 @@ function SpriteFrameTest.onEnter()
SpriteFrameTest.m_pSprite2:setFlipY(false) SpriteFrameTest.m_pSprite2:setFlipY(false)
performWithDelay(playerLayer,SpriteFrameTest.startIn05Secs, 0.5) performWithDelay(Helper.currentLayer,SpriteFrameTest.startIn05Secs, 0.5)
SpriteFrameTest.m_nCounter = 0 SpriteFrameTest.m_nCounter = 0
local scheduler = CCDirector:sharedDirector():getScheduler()
scheduler:unscheduleScriptEntry(SpriteFrameTest.entry)
end end
function SpriteFrameTest.onExit() function SpriteFrameTest.onExit()
@ -412,7 +302,7 @@ function SpriteFrameTest.onExit()
end end
function SpriteFrameTest.startIn05Secs(dt) function SpriteFrameTest.startIn05Secs(dt)
schedule(playerLayer,SpriteFrameTest.flipSprites, 1) schedule(Helper.currentLayer,SpriteFrameTest.flipSprites, 1)
end end
function SpriteFrameTest.flipSprites(dt) function SpriteFrameTest.flipSprites(dt)
@ -444,20 +334,19 @@ end
function SpriteFrameTest.onEnterOrExit(tag) function SpriteFrameTest.onEnterOrExit(tag)
local scheduler = CCDirector:sharedDirector():getScheduler()
if tag == "enter" then if tag == "enter" then
SpriteFrameTest.entry = scheduler:scheduleScriptFunc(SpriteFrameTest.onEnter, 0, false) SpriteFrameTest.onEnter()
elseif tag == "exit" then elseif tag == "exit" then
scheduler:unscheduleScriptEntry(SpriteFrameTest.entry) SpriteFrameTest.onExit()
end end
end end
function SpriteFrameTest.create() function SpriteFrameTest.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer:registerScriptHandler(SpriteFrameTest.onEnterOrExit) layer:registerScriptHandler(SpriteFrameTest.onEnterOrExit)
titleLabel:setString("Sprite vs. SpriteBatchNode animation") Helper.titleLabel:setString("Sprite vs. SpriteBatchNode animation")
return layer return layer
end end
@ -483,7 +372,7 @@ function SpriteFrameAliasNameTest.onEnter()
cclog("spriteBatch = " .. tostring(tolua.isnull(spriteBatch))) cclog("spriteBatch = " .. tostring(tolua.isnull(spriteBatch)))
cclog("sprite = " .. tostring(tolua.isnull(sprite))) cclog("sprite = " .. tostring(tolua.isnull(sprite)))
spriteBatch:addChild(sprite) spriteBatch:addChild(sprite)
playerLayer:addChild(spriteBatch) Helper.currentLayer:addChild(spriteBatch)
local animFrames = CCArray:createWithCapacity(15) local animFrames = CCArray:createWithCapacity(15)
for i = 1,14 do for i = 1,14 do
@ -494,9 +383,6 @@ function SpriteFrameAliasNameTest.onEnter()
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3) local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
-- 14 frames * 1sec = 14 seconds -- 14 frames * 1sec = 14 seconds
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation))) sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
local scheduler = CCDirector:sharedDirector():getScheduler()
scheduler:unscheduleScriptEntry(SpriteFrameAliasNameTest.entry)
end end
function SpriteFrameAliasNameTest.onExit() function SpriteFrameAliasNameTest.onExit()
@ -504,21 +390,20 @@ function SpriteFrameAliasNameTest.onExit()
end end
function SpriteFrameAliasNameTest.onEnterOrExit(tag) function SpriteFrameAliasNameTest.onEnterOrExit(tag)
local scheduler = CCDirector:sharedDirector():getScheduler()
if tag == "enter" then if tag == "enter" then
SpriteFrameAliasNameTest.entry = scheduler:scheduleScriptFunc(SpriteFrameAliasNameTest.onEnter, 0, false) SpriteFrameAliasNameTest.onEnter()
elseif tag == "exit" then elseif tag == "exit" then
scheduler:unscheduleScriptEntry(SpriteFrameAliasNameTest.entry) SpriteFrameAliasNameTest.onExit()
end end
end end
function SpriteFrameAliasNameTest.create() function SpriteFrameAliasNameTest.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer:registerScriptHandler(SpriteFrameAliasNameTest.onEnterOrExit) layer:registerScriptHandler(SpriteFrameAliasNameTest.onEnterOrExit)
titleLabel:setString("SpriteFrame Alias Name") Helper.titleLabel:setString("SpriteFrame Alias Name")
subtitleLabel:setString("SpriteFrames are obtained using the alias name") Helper.subtitleLabel:setString("SpriteFrames are obtained using the alias name")
return layer return layer
end end
@ -565,11 +450,11 @@ end
function SpriteAnchorPoint.create() function SpriteAnchorPoint.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteAnchorPoint.initLayer(layer) layer = SpriteAnchorPoint.initLayer(layer)
titleLabel:setString("Sprite: anchor point") Helper.titleLabel:setString("Sprite: anchor point")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -618,11 +503,11 @@ end
function SpriteBatchNodeAnchorPoint.create() function SpriteBatchNodeAnchorPoint.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteBatchNodeAnchorPoint.initLayer(layer) layer = SpriteBatchNodeAnchorPoint.initLayer(layer)
titleLabel:setString("SpriteBatchNode: anchor point") Helper.titleLabel:setString("SpriteBatchNode: anchor point")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -682,11 +567,11 @@ end
function SpriteOffsetAnchorRotation.create() function SpriteOffsetAnchorRotation.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteOffsetAnchorRotation.initLayer(layer) layer = SpriteOffsetAnchorRotation.initLayer(layer)
titleLabel:setString("Sprite offset + anchor + rot") Helper.titleLabel:setString("Sprite offset + anchor + rot")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -751,11 +636,11 @@ end
function SpriteBatchNodeOffsetAnchorRotation.create() function SpriteBatchNodeOffsetAnchorRotation.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteBatchNodeOffsetAnchorRotation.initLayer(layer) layer = SpriteBatchNodeOffsetAnchorRotation.initLayer(layer)
titleLabel:setString("SpriteBatchNode offset + anchor + rot") Helper.titleLabel:setString("SpriteBatchNode offset + anchor + rot")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -820,11 +705,11 @@ end
function SpriteOffsetAnchorScale.create() function SpriteOffsetAnchorScale.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteOffsetAnchorScale.initLayer(layer) layer = SpriteOffsetAnchorScale.initLayer(layer)
titleLabel:setString("Sprite offset + anchor + scale") Helper.titleLabel:setString("Sprite offset + anchor + scale")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -902,12 +787,12 @@ end
function SpriteBatchNodeOffsetAnchorScale.create() function SpriteBatchNodeOffsetAnchorScale.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorScale.eventHandler) layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorScale.eventHandler)
layer = SpriteBatchNodeOffsetAnchorScale.initLayer(layer) layer = SpriteBatchNodeOffsetAnchorScale.initLayer(layer)
titleLabel:setString("SpriteBatchNode offset + anchor + scale") Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -981,11 +866,11 @@ end
function SpriteOffsetAnchorSkew.create() function SpriteOffsetAnchorSkew.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteOffsetAnchorSkew.initLayer(layer) layer = SpriteOffsetAnchorSkew.initLayer(layer)
titleLabel:setString("SpriteBatchNode offset + anchor + scale") Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -1054,11 +939,11 @@ end
function SpriteOffsetAnchorRotationalSkew.create() function SpriteOffsetAnchorRotationalSkew.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteOffsetAnchorRotationalSkew.initLayer(layer) layer = SpriteOffsetAnchorRotationalSkew.initLayer(layer)
titleLabel:setString("Sprite offset + anchor + rotational skew") Helper.titleLabel:setString("Sprite offset + anchor + rotational skew")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -1133,11 +1018,11 @@ end
function SpriteBatchNodeOffsetAnchorSkew.create() function SpriteBatchNodeOffsetAnchorSkew.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteBatchNodeOffsetAnchorSkew.initLayer(layer) layer = SpriteBatchNodeOffsetAnchorSkew.initLayer(layer)
titleLabel:setString("SpriteBatchNode offset + anchor + skew") Helper.titleLabel:setString("SpriteBatchNode offset + anchor + skew")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -1212,11 +1097,11 @@ end
function SpriteBatchNodeOffsetAnchorRotationalSkew.create() function SpriteBatchNodeOffsetAnchorRotationalSkew.create()
local layer = CCLayer:create() local layer = CCLayer:create()
initWithLayer(layer) Helper.initWithLayer(layer)
layer = SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer) layer = SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer)
titleLabel:setString("SSpriteBatchNode offset + anchor + rot skew") Helper.titleLabel:setString("SSpriteBatchNode offset + anchor + rot skew")
subtitleLabel:setString("") Helper.subtitleLabel:setString("")
return layer return layer
end end
@ -1224,7 +1109,7 @@ end
function SpriteTest() function SpriteTest()
local scene = CCScene:create() local scene = CCScene:create()
createFunctionTable = { Helper.createFunctionTable = {
Sprite1.create, Sprite1.create,
SpriteBatchNode1.create, SpriteBatchNode1.create,
SpriteFrameTest.create, SpriteFrameTest.create,
@ -1242,7 +1127,7 @@ function SpriteTest()
} }
ActionIdx = 0 ActionIdx = 0
scene:addChild(nextAction()) scene:addChild(Sprite1.create())
scene:addChild(CreateBackMenuItem()) scene:addChild(CreateBackMenuItem())
return scene return scene

View File

@ -35,3 +35,73 @@ function CreateBackMenuItem()
return Menu return Menu
end 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