axmol/samples/Lua/TestLua/Resources/luaScript/NodeTest/NodeTest.lua

658 lines
19 KiB
Lua
Raw Normal View History

2012-08-31 18:26:27 +08:00
local kTagSprite1 = 1
local kTagSprite2 = 2
local kTagSprite3 = 3
local kTagSlider = 4
local s = cc.Director:getInstance():getWinSize()
local scheduler = cc.Director:getInstance():getScheduler()
2012-08-31 18:26:27 +08:00
local function getBaseLayer()
local layer = cc.Layer:create()
2012-08-31 18:26:27 +08:00
2013-03-13 17:45:09 +08:00
Helper.initWithLayer(layer)
2012-08-31 18:26:27 +08:00
2013-03-13 17:45:09 +08:00
return layer
2012-08-31 18:26:27 +08:00
end
-----------------------------------
-- CameraCenterTest
-----------------------------------
local function CameraCenterTest()
local layer = getBaseLayer()
-- LEFT-TOP
local sprite = cc.Sprite:create("Images/white-512x512.png")
2012-08-31 18:26:27 +08:00
layer:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 5 * 1, s.height / 5 * 1))
sprite:setColor(cc.c3b(255, 0, 0))
sprite:setTextureRect(cc.rect(0, 0, 120, 50))
local orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
-- [sprite setAnchorPoint: cc.p(0,1))
2012-08-31 18:26:27 +08:00
-- LEFT-BOTTOM
sprite = cc.Sprite:create("Images/white-512x512.png")
2012-08-31 18:26:27 +08:00
layer:addChild(sprite, 0, 40)
sprite:setPosition(cc.p(s.width / 5 * 1, s.height / 5 * 4))
sprite:setColor(cc.c3b(0, 0, 255))
sprite:setTextureRect(cc.rect(0, 0, 120, 50))
orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- RIGHT-TOP
sprite = cc.Sprite:create("Images/white-512x512.png")
2012-08-31 18:26:27 +08:00
layer:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 5 * 4, s.height / 5 * 1))
sprite:setColor(cc.c3b(255, 255, 0))
sprite:setTextureRect(cc.rect(0, 0, 120, 50))
orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- RIGHT-BOTTOM
sprite = cc.Sprite:create("Images/white-512x512.png")
2012-08-31 18:26:27 +08:00
layer:addChild(sprite, 0, 40)
sprite:setPosition(cc.p(s.width / 5 * 4, s.height / 5 * 4))
sprite:setColor(cc.c3b(0, 255, 0))
sprite:setTextureRect(cc.rect(0, 0, 120, 50))
orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- CENTER
sprite = cc.Sprite:create("Images/white-512x512.png")
2012-08-31 18:26:27 +08:00
layer:addChild(sprite, 0, 40)
sprite:setPosition(cc.p(s.width / 2, s.height / 2))
sprite:setColor(cc.c3b(255, 255, 255))
sprite:setTextureRect(cc.rect(0, 0, 120, 50))
orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Camera Center test")
Helper.subtitleLabel:setString("Sprites should rotate at the same speed")
2012-08-31 18:26:27 +08:00
return layer
end
-----------------------------------
-- Test2
-----------------------------------
local function Test2()
local layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp2 = cc.Sprite:create(s_pPathSister2)
local sp3 = cc.Sprite:create(s_pPathSister1)
local sp4 = cc.Sprite:create(s_pPathSister2)
2012-08-31 18:26:27 +08:00
sp1:setPosition(cc.p(100, s.height /2))
sp2:setPosition(cc.p(380, s.height /2))
2012-08-31 18:26:27 +08:00
layer:addChild(sp1)
layer:addChild(sp2)
sp3:setScale(0.25)
sp4:setScale(0.25)
sp1:addChild(sp3)
sp2:addChild(sp4)
local a1 = cc.RotateBy:create(2, 360)
local a2 = cc.ScaleBy:create(2, 2)
2012-08-31 18:26:27 +08:00
local action1 = cc.RepeatForever:create(cc.Sequence:create(a1, a2, a2:reverse()))
local action2 = cc.RepeatForever:create(cc.Sequence:create(a1:clone(), a2:clone(), a2:reverse()))
2012-08-31 18:26:27 +08:00
sp2:setAnchorPoint(cc.p(0,0))
2012-08-31 18:26:27 +08:00
sp1:runAction(action1)
sp2:runAction(action2)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("anchorPoint and children")
2012-08-31 18:26:27 +08:00
return layer
end
-----------------------------------
-- Test4
-----------------------------------
local Test4_layer = nil
local Test4_delay2Entry = nil
local Test4_delay4Entry = nil
local function delay2(dt)
node = Test4_layer:getChildByTag(2)
local action1 = cc.RotateBy:create(1, 360)
2012-08-31 18:26:27 +08:00
node:runAction(action1)
end
local function delay4(dt)
scheduler:unscheduleScriptEntry(Test4_delay4Entry)
Test4_layer:removeChildByTag(3, false)
end
local function Test4_onEnterOrExit(tag)
if tag == "enter" then
2012-08-31 18:26:27 +08:00
Test4_delay2Entry = scheduler:scheduleScriptFunc(delay2, 2.0, false)
Test4_delay4Entry = scheduler:scheduleScriptFunc(delay4, 4.0, false)
elseif tag == "exit" then
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(Test4_delay2Entry)
scheduler:unscheduleScriptEntry(Test4_delay4Entry)
end
end
local function Test4()
Test4_layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp2 = cc.Sprite:create(s_pPathSister2)
sp1:setPosition(cc.p(100, 160))
sp2:setPosition(cc.p(380, 160))
2012-08-31 18:26:27 +08:00
Test4_layer:addChild(sp1, 0, 2)
Test4_layer:addChild(sp2, 0, 3)
Test4_layer:registerScriptHandler(Test4_onEnterOrExit)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("tags")
2012-08-31 18:26:27 +08:00
return Test4_layer
end
-----------------------------------
-- Test5
-----------------------------------
local Test5_entry = nil
local Test5_layer = nil
local function Test5_addAndRemove(dt)
local sp1 = Test5_layer:getChildByTag(kTagSprite1)
local sp2 = Test5_layer:getChildByTag(kTagSprite2)
sp1:retain()
sp2:retain()
Test5_layer:removeChild(sp1, false)
Test5_layer:removeChild(sp2, true)
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2)
sp1:release()
sp2:release()
end
local function Test5_onEnterOrExit(tag)
if tag == "enter" then
2012-08-31 18:26:27 +08:00
Test5_entry = scheduler:scheduleScriptFunc(Test5_addAndRemove, 2.0, false)
elseif tag == "exit" then
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(Test5_entry)
end
end
local function Test5()
Test5_layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp2 = cc.Sprite:create(s_pPathSister2)
2012-08-31 18:26:27 +08:00
sp1:setPosition(cc.p(100, 160))
sp2:setPosition(cc.p(380, 160))
2012-08-31 18:26:27 +08:00
local rot = cc.RotateBy:create(2, 360)
2012-08-31 18:26:27 +08:00
local rot_back = rot:reverse()
local forever = cc.RepeatForever:create(cc.Sequence:create(rot, rot_back))
local rot2 = cc.RotateBy:create(2, 360)
local rot2_back = rot2:reverse()
local forever2 = cc.RepeatForever:create(cc.Sequence:create(rot2, rot2_back))
2012-08-31 18:26:27 +08:00
forever:setTag(101)
forever2:setTag(102)
Test5_layer:addChild(sp1, 0, kTagSprite1)
Test5_layer:addChild(sp2, 0, kTagSprite2)
sp1:runAction(forever)
sp2:runAction(forever2)
Test5_layer:registerScriptHandler(Test5_onEnterOrExit)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("remove and cleanup")
2012-08-31 18:26:27 +08:00
return Test5_layer
end
-----------------------------------
-- Test6
-----------------------------------
local Test6_entry = nil
local Test6_layer = nil
local function Test6_addAndRemove(dt)
local sp1 = Test6_layer:getChildByTag(kTagSprite1)
local sp2 = Test6_layer:getChildByTag(kTagSprite2)
sp1:retain()
sp2:retain()
Test6_layer:removeChild(sp1, false)
Test6_layer:removeChild(sp2, true)
Test6_layer:addChild(sp1, 0, kTagSprite1)
Test6_layer:addChild(sp2, 0, kTagSprite2)
sp1:release()
sp2:release()
end
local function Test6_onEnterOrExit(tag)
if tag == "enter" then
2012-08-31 18:26:27 +08:00
Test6_entry = scheduler:scheduleScriptFunc(Test6_addAndRemove, 2.0, false)
elseif tag == "exit" then
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(Test6_entry)
end
end
local function Test6()
Test6_layer = getBaseLayer()
local sp1 = cc.Sprite:create(s_pPathSister1)
local sp11 = cc.Sprite:create(s_pPathSister1)
2012-08-31 18:26:27 +08:00
local sp2 = cc.Sprite:create(s_pPathSister2)
local sp21 = cc.Sprite:create(s_pPathSister2)
2012-08-31 18:26:27 +08:00
sp1:setPosition(cc.p(100, 160))
sp2:setPosition(cc.p(380, 160))
2012-08-31 18:26:27 +08:00
local rot = cc.RotateBy:create(2, 360)
2012-08-31 18:26:27 +08:00
local rot_back = rot:reverse()
local forever1 = cc.RepeatForever:create(cc.Sequence:create(rot, rot_back))
local forever11 = tolua.cast(forever1:clone(), "RepeatForever")
2012-08-31 18:26:27 +08:00
local forever2 = tolua.cast(forever1:clone(), "RepeatForever")
local forever21 = tolua.cast(forever1:clone(), "RepeatForever")
2012-08-31 18:26:27 +08:00
Test6_layer:addChild(sp1, 0, kTagSprite1)
sp1:addChild(sp11)
Test6_layer:addChild(sp2, 0, kTagSprite2)
sp2:addChild(sp21)
sp1:runAction(forever1)
sp11:runAction(forever11)
sp2:runAction(forever2)
sp21:runAction(forever21)
Test6_layer:registerScriptHandler(Test6_onEnterOrExit)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("remove/cleanup with children")
2012-08-31 18:26:27 +08:00
return Test6_layer
end
-----------------------------------
-- StressTest1
-----------------------------------
local StressTest1_entry = nil
local StressTest1_layer = nil
local function removeMe(node)
local parent = StressTest1_layer:getParent()
parent:removeChild(node, true)
2013-03-13 17:45:09 +08:00
Helper.nextAction()
2012-08-31 18:26:27 +08:00
end
local function shouldNotCrash(dt)
scheduler:unscheduleScriptEntry(StressTest1_entry)
-- if the node has timers, it crashes
local explosion = cc.ParticleSun:create()
explosion:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
2012-08-31 18:26:27 +08:00
explosion:setPosition(s.width / 2, s.height / 2)
StressTest1_layer:setAnchorPoint(cc.p(0, 0))
local callFunc = cc.CallFunc:create(removeMe)
StressTest1_layer:runAction(cc.Sequence:create(cc.RotateBy:create(2, 360), callFunc))
2012-08-31 18:26:27 +08:00
StressTest1_layer:addChild(explosion)
end
local function StressTest1_onEnterOrExit(tag)
if tag == "enter" then
2012-08-31 18:26:27 +08:00
StressTest1_entry = scheduler:scheduleScriptFunc(shouldNotCrash, 1.0, false)
elseif tag == "exit" then
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(StressTest1_entry)
end
end
local function StressTest1()
StressTest1_layer = getBaseLayer()
sp1 = cc.Sprite:create(s_pPathSister1)
2012-08-31 18:26:27 +08:00
StressTest1_layer:addChild(sp1, 0, kTagSprite1)
sp1:setPosition(cc.p(s.width / 2, s.height / 2))
2012-08-31 18:26:27 +08:00
StressTest1_layer:registerScriptHandler(StressTest1_onEnterOrExit)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("stress test #1: no crashes")
2012-08-31 18:26:27 +08:00
return StressTest1_layer
end
-----------------------------------
-- StressTest2
-----------------------------------
local StressTest2_entry = nil
local StressTest2_layer = nil
local function shouldNotLeak(dt)
scheduler:unscheduleScriptEntry(StressTest2_entry)
local sublayer = StressTest2_layer:getChildByTag(kTagSprite1)
sublayer:removeAllChildrenWithCleanup(true)
end
local function StressTest2_onEnterOrExit(tag)
if tag == "enter" then
2012-08-31 18:26:27 +08:00
StressTest2_entry = scheduler:scheduleScriptFunc(shouldNotLeak, 6.0, false)
elseif tag == "exit" then
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(StressTest2_entry)
end
end
local function StressTest2()
StressTest2_layer = getBaseLayer()
sublayer = cc.Layer:create()
2012-08-31 18:26:27 +08:00
local sp1 = cc.Sprite:create(s_pPathSister1)
sp1:setPosition(cc.p(80, s.height / 2))
2012-08-31 18:26:27 +08:00
local move = cc.MoveBy:create(3, cc.p(350, 0))
local move_ease_inout3 = cc.EaseInOut:create(cc.MoveBy:create(3, cc.p(350, 0)), 2.0)
2012-08-31 18:26:27 +08:00
local move_ease_inout_back3 = move_ease_inout3:reverse()
local seq3 = cc.Sequence:create(move_ease_inout3, move_ease_inout_back3)
sp1:runAction(cc.RepeatForever:create(seq3))
2012-08-31 18:26:27 +08:00
sublayer:addChild(sp1, 1)
local fire = cc.ParticleFire:create()
fire:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
fire = tolua.cast(fire, "Node")
2012-08-31 18:26:27 +08:00
fire:setPosition(80, s.height / 2 - 50)
local copy_seq3 = tolua.cast(seq3:clone(), "Sequence")
fire:runAction(cc.RepeatForever:create(copy_seq3))
2012-08-31 18:26:27 +08:00
sublayer:addChild(fire, 2)
StressTest2_layer:registerScriptHandler(StressTest2_onEnterOrExit)
StressTest2_layer:addChild(sublayer, 0, kTagSprite1)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("stress test #2: no leaks")
2012-08-31 18:26:27 +08:00
return StressTest2_layer
end
-----------------------------------
-- NodeToWorld
-----------------------------------
local function NodeToWorld()
local layer = getBaseLayer()
-- This code tests that nodeToParent works OK:
-- - It tests different anchor Points
-- - It tests different children anchor points
local back = cc.Sprite:create(s_back3)
2012-08-31 18:26:27 +08:00
layer:addChild(back, -10)
back:setAnchorPoint(cc.p(0, 0))
2012-08-31 18:26:27 +08:00
local backSize = back:getContentSize()
local item = cc.MenuItemImage:create(s_PlayNormal, s_PlaySelect)
local menu = cc.Menu:create()
2012-08-31 18:26:27 +08:00
menu:addChild(item)
menu:alignItemsVertically()
menu:setPosition(cc.p(backSize.width / 2, backSize.height / 2))
2012-08-31 18:26:27 +08:00
back:addChild(menu)
local rot = cc.RotateBy:create(5, 360)
local fe = cc.RepeatForever:create(rot)
2012-08-31 18:26:27 +08:00
item:runAction(fe)
local move = cc.MoveBy:create(3, cc.p(200, 0))
2012-08-31 18:26:27 +08:00
local move_back = move:reverse()
local seq = cc.Sequence:create(move, move_back)
local fe2 = cc.RepeatForever:create(seq)
2012-08-31 18:26:27 +08:00
back:runAction(fe2)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("nodeToParent transform")
2012-08-31 18:26:27 +08:00
return layer
end
-----------------------------------
-- CameraOrbitTest
-----------------------------------
local function CameraOrbitTest_onEnterOrExit(tag)
if tag == "enter" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION3_D)
elseif tag == "exit" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION2_D)
2012-08-31 18:26:27 +08:00
end
end
local function CameraOrbitTest()
local layer = getBaseLayer()
local p = cc.Sprite:create(s_back3)
2012-08-31 18:26:27 +08:00
layer:addChild(p, 0)
p:setPosition(cc.p(s.width / 2, s.height / 2))
2012-08-31 18:26:27 +08:00
p:setOpacity(128)
-- LEFT
local s = p:getContentSize()
local sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
sprite:setScale(0.5)
p:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 4 * 1, s.height / 2))
local orbit = cc.OrbitCamera:create(2, 1, 0, 0, 360, 0, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- CENTER
sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
sprite:setScale(1.0)
p:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 4 * 2, s.height / 2))
orbit = cc.OrbitCamera:create(2, 1, 0, 0, 360, 45, 0)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- RIGHT
sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
sprite:setScale(2.0)
p:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 4 * 3, s.height / 2))
2012-08-31 18:26:27 +08:00
local ss = sprite:getContentSize()
orbit = cc.OrbitCamera:create(2, 1, 0, 0, 360, 90, -45)
sprite:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
-- PARENT
orbit = cc.OrbitCamera:create(10, 1, 0, 0, 360, 0, 90)
p:runAction(cc.RepeatForever:create(orbit))
2012-08-31 18:26:27 +08:00
layer:setScale(1)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Camera Orbit test")
2012-08-31 18:26:27 +08:00
return layer
end
-----------------------------------
-- CameraZoomTest
-----------------------------------
local z = 0
local CameraZoomTest_layer = nil
local CameraZoomTest_entry = nil
local function CameraZoomTest_update(dt)
z = z + dt * 100
local sprite = CameraZoomTest_layer:getChildByTag(20)
-- local cam = sprite:getCamera()
-- cam:setEye(0, 0, z)
2012-08-31 18:26:27 +08:00
sprite = CameraZoomTest_layer:getChildByTag(40)
-- cam = sprite:getCamera()
-- cam:setEye(0, 0, -z)
2012-08-31 18:26:27 +08:00
end
local function CameraZoomTest_onEnterOrExit(tag)
if tag == "enter" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION3_D)
2012-08-31 18:26:27 +08:00
CameraZoomTest_entry = scheduler:scheduleScriptFunc(CameraZoomTest_update, 0.0, false)
elseif tag == "exit" then
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION2_D)
2012-08-31 18:26:27 +08:00
scheduler:unscheduleScriptEntry(CameraZoomTest_entry)
end
end
local function CameraZoomTest()
CameraZoomTest_layer = getBaseLayer()
z = 0
-- LEFT
local sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
CameraZoomTest_layer:addChild(sprite, 0)
sprite:setPosition(cc.p(s.width / 4 * 1, s.height / 2))
-- local cam = sprite:getCamera()
-- cam:setEye(0, 0, 415 / 2)
-- cam:setCenter(0, 0, 0)
2012-08-31 18:26:27 +08:00
-- CENTER
sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
CameraZoomTest_layer:addChild(sprite, 0, 40)
sprite:setPosition(cc.p(s.width / 4 * 2, s.height / 2))
2012-08-31 18:26:27 +08:00
-- RIGHT
sprite = cc.Sprite:create(s_pPathGrossini)
2012-08-31 18:26:27 +08:00
CameraZoomTest_layer:addChild(sprite, 0, 20)
sprite:setPosition(cc.p(s.width / 4 * 3, s.height / 2))
2012-08-31 18:26:27 +08:00
CameraZoomTest_layer:scheduleUpdateWithPriorityLua(CameraZoomTest_update, 0)
2012-08-31 18:26:27 +08:00
CameraZoomTest_layer:registerScriptHandler(CameraZoomTest_onEnterOrExit)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Camera Zoom test")
2012-08-31 18:26:27 +08:00
return CameraZoomTest_layer
end
-----------------------------------
-- ConvertToNode
-----------------------------------
local ConvertToNode_layer = nil
local function ConvertToNode()
ConvertToNode_layer = getBaseLayer()
local rotate = cc.RotateBy:create(10, 360)
local action = cc.RepeatForever:create(rotate)
2012-08-31 18:26:27 +08:00
for i = 0, 2 do
local sprite = cc.Sprite:create("Images/grossini.png")
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
2012-08-31 18:26:27 +08:00
local point = cc.Sprite:create("Images/r1.png")
2012-08-31 18:26:27 +08:00
point:setScale(0.25)
point:setPosition(sprite:getPosition())
ConvertToNode_layer:addChild(point, 10, 100 + i)
if i == 0 then
sprite:setAnchorPoint(cc.p(0, 0))
2012-08-31 18:26:27 +08:00
elseif i == 1 then
sprite:setAnchorPoint(cc.p(0.5, 0.5))
2012-08-31 18:26:27 +08:00
elseif i == 2 then
sprite:setAnchorPoint(cc.p(1,1))
2012-08-31 18:26:27 +08:00
end
point:setPosition(sprite:getPosition())
local copy = tolua.cast(action:clone(), "RepeatForever")
2012-08-31 18:26:27 +08:00
sprite:runAction(copy)
ConvertToNode_layer:addChild(sprite, i)
end
local function onTouchEnded(x, y)
for i = 0, 2 do
local node = ConvertToNode_layer:getChildByTag(100 + i)
local p1, p2
p1 = node:convertToNodeSpaceAR(cc.p(x, y))
p2 = node:convertToNodeSpace(cc.p(x, y))
2012-08-31 18:26:27 +08:00
cclog("AR: x=" .. p1.x .. ", y=" .. p1.y .. " -- Not AR: x=" .. p2.x .. ", y=" .. p2.y)
end
end
local function onTouch(eventType, x, y)
if eventType == "began" then
2012-08-31 18:26:27 +08:00
return true
elseif eventType == "ended" then
2012-08-31 18:26:27 +08:00
return onTouchEnded(x, y)
end
end
ConvertToNode_layer:setTouchEnabled(true)
ConvertToNode_layer:registerScriptTouchHandler(onTouch)
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Convert To Node Space")
Helper.subtitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console")
2012-08-31 18:26:27 +08:00
return ConvertToNode_layer
end
-----------------------------------
-- NodeOpaqueTest
-----------------------------------
local function NodeOpaqueTest()
local layer = getBaseLayer()
for i = 0, 49 do
local background = cc.Sprite:create("Images/background1.png")
background:setBlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
background:setAnchorPoint(cc.p(0, 0))
2012-08-31 18:26:27 +08:00
layer:addChild(background)
end
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Node Opaque Test")
Helper.subtitleLabel:setString("Node rendered with GL_BLEND disabled")
2012-08-31 18:26:27 +08:00
return layer
end
-----------------------------------
-- NodeNonOpaqueTest
-----------------------------------
local function NodeNonOpaqueTest()
local layer = getBaseLayer()
for i = 0, 49 do
background = cc.Sprite:create("Images/background1.jpg")
background:setBlendFunc(gl.ONE, gl.ZERO)
background:setAnchorPoint(cc.p(0, 0))
2012-08-31 18:26:27 +08:00
layer:addChild(background)
end
2013-03-13 17:45:09 +08:00
Helper.titleLabel:setString("Node Non Opaque Test")
Helper.subtitleLabel:setString("Node rendered with GL_BLEND enabled")
2012-08-31 18:26:27 +08:00
return layer
end
function CocosNodeTest()
local scene = cc.Scene:create()
2012-08-31 18:26:27 +08:00
2013-03-13 17:45:09 +08:00
Helper.createFunctionTable = {
CameraCenterTest,
Test2,
Test4,
Test5,
Test6,
StressTest1,
StressTest2,
NodeToWorld,
CameraOrbitTest,
CameraZoomTest,
ConvertToNode,
NodeOpaqueTest,
NodeNonOpaqueTest
}
scene:addChild(CameraCenterTest())
2012-08-31 18:26:27 +08:00
scene:addChild(CreateBackMenuItem())
return scene
end