2013-04-07 10:38:56 +08:00
|
|
|
local kTagTextLayer = 1
|
|
|
|
local kTagSprite1 = 1
|
|
|
|
local kTagSprite2 = 2
|
|
|
|
local kTagBackground = 1
|
|
|
|
local kTagLabel = 2
|
|
|
|
|
|
|
|
local originCreateLayer = createTestLayer
|
|
|
|
|
|
|
|
local function createTestLayer(title, subtitle)
|
|
|
|
local ret = originCreateLayer(title, subtitle)
|
2014-01-04 15:46:04 +08:00
|
|
|
local bgNode = cc.NodeGrid:create()
|
|
|
|
bgNode:setAnchorPoint(cc.p(0.5,0.5))
|
|
|
|
ret:addChild(bgNode,0,kTagBackground)
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local bg = cc.Sprite:create("Images/background3.png")
|
2014-01-04 15:46:04 +08:00
|
|
|
bg:setPosition( VisibleRect:center())
|
|
|
|
bgNode:addChild(bg)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2014-01-04 15:46:04 +08:00
|
|
|
local target1 = cc.NodeGrid:create()
|
|
|
|
target1:setAnchorPoint(cc.p(0.5,0.5))
|
2013-08-15 15:51:22 +08:00
|
|
|
local grossini = cc.Sprite:create("Images/grossinis_sister2.png")
|
2014-01-04 15:46:04 +08:00
|
|
|
target1:addChild(grossini)
|
|
|
|
bgNode:addChild(target1,1,kTagSprite1)
|
|
|
|
target1:setPosition(cc.p(VisibleRect:left().x+VisibleRect:getVisibleRect().width/3.0, VisibleRect:bottom().y+ 200) )
|
2013-08-15 15:51:22 +08:00
|
|
|
local sc = cc.ScaleBy:create(2, 5)
|
2013-04-07 10:38:56 +08:00
|
|
|
local sc_back = sc:reverse()
|
2014-01-04 15:46:04 +08:00
|
|
|
target1:runAction( cc.RepeatForever:create(cc.Sequence:create(sc, sc_back)))
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2014-01-04 15:46:04 +08:00
|
|
|
local target2 = cc.NodeGrid:create()
|
|
|
|
target2:setAnchorPoint(cc.p(0.5,0.5))
|
2013-08-15 15:51:22 +08:00
|
|
|
local tamara = cc.Sprite:create("Images/grossinis_sister1.png")
|
2014-01-04 15:46:04 +08:00
|
|
|
target2:addChild(tamara)
|
|
|
|
bgNode:addChild(target2,1,kTagSprite2)
|
|
|
|
target2:setPosition( cc.p(VisibleRect:left().x+2*VisibleRect:getVisibleRect().width/3.0,VisibleRect:bottom().y+200) )
|
2013-08-15 15:51:22 +08:00
|
|
|
local sc2 = cc.ScaleBy:create(2, 5)
|
2013-04-07 10:38:56 +08:00
|
|
|
local sc2_back = sc2:reverse()
|
2014-01-04 15:46:04 +08:00
|
|
|
target2:runAction( cc.RepeatForever:create(cc.Sequence:create(sc2, sc2_back)))
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Effect1
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function Effect1()
|
|
|
|
local ret = createTestLayer("Lens + Waves3d and OrbitCamera")
|
|
|
|
local target = ret:getChildByTag(kTagBackground)
|
|
|
|
|
|
|
|
-- To reuse a grid the grid size and the grid type must be the same.
|
|
|
|
-- in this case:
|
|
|
|
-- Lens3D is Grid3D and it's size is (15,10)
|
|
|
|
-- Waves3D is Grid3D and it's size is (15,10)
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
|
|
|
local lens = cc.Lens3D:create(0.0, cc.size(15,10), cc.p(size.width/2,size.height/2), 240)
|
|
|
|
local waves = cc.Waves3D:create(10, cc.size(15,10), 18, 15)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local reuse = cc.ReuseGrid:create(1)
|
|
|
|
local delay = cc.DelayTime:create(8)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2014-01-04 15:46:04 +08:00
|
|
|
-- local orbit = cc.OrbitCamera:create(5, 1, 2, 0, 180, 0, -90)
|
|
|
|
-- local orbit_back = orbit:reverse()
|
|
|
|
-- target:runAction( cc.RepeatForever:create( cc.Sequence:create(orbit, orbit_back)))
|
2013-08-15 15:51:22 +08:00
|
|
|
target:runAction( cc.Sequence:create(lens, delay, reuse, waves))
|
2013-04-07 10:38:56 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Effect2
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function Effect2()
|
|
|
|
local ret = createTestLayer("ShakyTiles + ShuffleTiles + TurnOffTiles")
|
|
|
|
local target = ret:getChildByTag(kTagBackground)
|
|
|
|
|
|
|
|
-- To reuse a grid the grid size and the grid type must be the same.
|
|
|
|
-- in this case:
|
|
|
|
-- ShakyTiles is TiledGrid3D and it's size is (15,10)
|
|
|
|
-- Shuffletiles is TiledGrid3D and it's size is (15,10)
|
|
|
|
-- TurnOfftiles is TiledGrid3D and it's size is (15,10)
|
2013-08-15 15:51:22 +08:00
|
|
|
local shaky = cc.ShakyTiles3D:create(5, cc.size(15,10), 4, false)
|
|
|
|
local shuffle = cc.ShuffleTiles:create(0, cc.size(15,10), 3)
|
|
|
|
local turnoff = cc.TurnOffTiles:create(0, cc.size(15,10), 3)
|
2013-04-07 10:38:56 +08:00
|
|
|
local turnon = turnoff:reverse()
|
|
|
|
|
|
|
|
-- reuse 2 times:
|
|
|
|
-- 1 for shuffle
|
|
|
|
-- 2 for turn off
|
|
|
|
-- turnon tiles will use a new grid
|
2013-08-15 15:51:22 +08:00
|
|
|
local reuse = cc.ReuseGrid:create(2)
|
|
|
|
|
|
|
|
local delay = cc.DelayTime:create(1)
|
|
|
|
|
|
|
|
target:runAction(cc.Sequence:create(shaky, delay ,reuse, shuffle, tolua.cast(delay:clone(), "Action"), turnoff, turnon))
|
2013-04-07 10:38:56 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Effect3
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function Effect3()
|
|
|
|
local ret = createTestLayer("Effects on 2 sprites")
|
|
|
|
local bg = ret:getChildByTag(kTagBackground)
|
|
|
|
local target1 = bg:getChildByTag(kTagSprite1)
|
|
|
|
local target2 = bg:getChildByTag(kTagSprite2)
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local waves = cc.Waves:create(5, cc.size(15,10), 5, 20, true, false)
|
|
|
|
local shaky = cc.Shaky3D:create(5, cc.size(15,10), 4, false)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
target1:runAction( cc.RepeatForever:create( waves ) )
|
|
|
|
target2:runAction( cc.RepeatForever:create( shaky ) )
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- moving background. Testing issue #244
|
2013-08-15 15:51:22 +08:00
|
|
|
local move = cc.MoveBy:create(3, cc.p(200,0) )
|
|
|
|
bg:runAction(cc.RepeatForever:create( cc.Sequence:create(move, move:reverse())))
|
2013-04-07 10:38:56 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Effect4
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
-- class Lens3DTarget : public cc.Node
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- public:
|
2013-08-30 11:56:35 +08:00
|
|
|
-- virtual void setPosition(const CCPoint& var)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- m_pLens3D:setPosition(var)
|
|
|
|
-- end
|
|
|
|
|
2013-08-30 11:56:35 +08:00
|
|
|
-- virtual const CCPoint& getPosition()
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- return m_pLens3D:getPosition()
|
|
|
|
-- end
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
-- static Lens3DTarget* create(cc.Lens3D* pAction)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- Lens3DTarget* pRet = new Lens3DTarget()
|
|
|
|
-- pRet:m_pLens3D = pAction
|
|
|
|
-- pRet:autorelease()
|
|
|
|
-- return pRet
|
|
|
|
-- end
|
|
|
|
-- private:
|
|
|
|
|
|
|
|
-- Lens3DTarget()
|
|
|
|
-- : m_pLens3D(NULL)
|
|
|
|
-- {}
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
-- cc.Lens3D* m_pLens3D
|
2013-04-07 10:38:56 +08:00
|
|
|
-- end
|
|
|
|
|
|
|
|
local function Effect4()
|
|
|
|
local ret = createTestLayer("Jumpy Lens3D")
|
2013-08-15 15:51:22 +08:00
|
|
|
local lens = cc.Lens3D:create(10, cc.size(32,24), cc.p(100,180), 150)
|
|
|
|
local move = cc.JumpBy:create(5, cc.p(380,0), 100, 4)
|
2013-04-07 10:38:56 +08:00
|
|
|
local move_back = move:reverse()
|
2013-08-15 15:51:22 +08:00
|
|
|
local seq = cc.Sequence:create( move, move_back)
|
|
|
|
|
|
|
|
-- /* In cocos2d-iphone, the type of action's target is 'id', so it supports using the instance of 'cc.Lens3D' as its target.
|
|
|
|
-- While in cocos2d-x, the target of action only supports cc.Node or its subclass,
|
|
|
|
-- so we make an encapsulation for cc.Lens3D to achieve that.
|
2013-04-07 10:38:56 +08:00
|
|
|
-- */
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local director = cc.Director:getInstance()
|
2013-04-07 10:38:56 +08:00
|
|
|
-- local pTarget = Lens3DTarget:create(lens)
|
|
|
|
-- -- Please make sure the target been added to its parent.
|
|
|
|
-- ret:addChild(pTarget)
|
|
|
|
|
|
|
|
-- director:getActionManager():addAction(seq, pTarget, false)
|
2014-01-04 15:46:04 +08:00
|
|
|
local bg = ret:getChildByTag(kTagBackground)
|
|
|
|
bg:runAction( lens )
|
2013-04-07 10:38:56 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Effect5
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function Effect5()
|
|
|
|
local ret = createTestLayer("Test Stop-Copy-Restar")
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local effect = cc.Liquid:create(2, cc.size(32,24), 1, 20)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local stopEffect = cc.Sequence:create(effect, cc.DelayTime:create(2), cc.StopGrid:create())
|
2013-04-07 10:38:56 +08:00
|
|
|
local bg = ret:getChildByTag(kTagBackground)
|
|
|
|
bg:runAction(stopEffect)
|
|
|
|
local function onNodeEvent(event)
|
|
|
|
if event == "exit" then
|
2013-08-15 15:51:22 +08:00
|
|
|
cc.Director:getInstance():setProjection(cc.DIRECTOR_PROJECTION_3D)
|
2013-04-07 10:38:56 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ret:registerScriptHandler(onNodeEvent)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Issue631
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local function Issue631()
|
|
|
|
local ret = createTestLayer("Testing Opacity",
|
|
|
|
"Effect image should be 100% opaque. Testing issue #631")
|
2013-08-15 15:51:22 +08:00
|
|
|
|
|
|
|
local effect = cc.Sequence:create(cc.DelayTime:create(2.0),cc.Shaky3D:create(5.0, cc.size(5, 5), 16, false))
|
2013-04-07 10:38:56 +08:00
|
|
|
|
|
|
|
-- cleanup
|
|
|
|
local bg = ret:getChildByTag(kTagBackground)
|
|
|
|
ret:removeChild(bg, true)
|
|
|
|
|
|
|
|
-- background
|
2013-08-15 15:51:22 +08:00
|
|
|
local layer = cc.LayerColor:create( cc.c4b(255,0,0,255) )
|
2013-04-07 10:38:56 +08:00
|
|
|
ret:addChild(layer, -10)
|
2013-08-15 15:51:22 +08:00
|
|
|
local sprite = cc.Sprite:create("Images/grossini.png")
|
|
|
|
sprite:setPosition( cc.p(50,80) )
|
2013-04-07 10:38:56 +08:00
|
|
|
layer:addChild(sprite, 10)
|
|
|
|
|
|
|
|
-- foreground
|
2014-01-04 15:46:04 +08:00
|
|
|
local layer2BaseGrid = cc.NodeGrid:create()
|
2013-08-15 15:51:22 +08:00
|
|
|
local layer2 = cc.LayerColor:create(cc.c4b( 0, 255,0,255 ) )
|
|
|
|
local fog = cc.Sprite:create("Images/Fog.png")
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
--local bf = BlendFunc()
|
|
|
|
--bf.src = GL_SRC_ALPHA
|
|
|
|
--bf.dst = GL_ONE_MINUS_SRC_ALPHA
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
fog:setBlendFunc(gl.SRC_ALPHA , gl.ONE_MINUS_SRC_ALPHA )
|
2013-04-07 10:38:56 +08:00
|
|
|
layer2:addChild(fog, 1)
|
2014-01-04 15:46:04 +08:00
|
|
|
ret:addChild(layer2BaseGrid, 1)
|
|
|
|
layer2BaseGrid:addChild(layer2)
|
2013-04-07 10:38:56 +08:00
|
|
|
|
2014-01-04 15:46:04 +08:00
|
|
|
layer2BaseGrid:runAction( cc.RepeatForever:create(effect) )
|
2013-04-07 10:38:56 +08:00
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function EffectAdvancedTestMain()
|
|
|
|
cclog("EffectAdvancedTestMain")
|
|
|
|
Helper.index = 1
|
|
|
|
|
2013-08-15 15:51:22 +08:00
|
|
|
local scene = cc.Scene:create()
|
2013-04-07 10:38:56 +08:00
|
|
|
Helper.createFunctionTable = {
|
|
|
|
Effect3,
|
|
|
|
Effect2,
|
|
|
|
Effect1,
|
|
|
|
Effect4,
|
|
|
|
Effect5,
|
|
|
|
Issue631
|
|
|
|
}
|
|
|
|
scene:addChild(Effect3())
|
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
return scene
|
|
|
|
end
|