2013-08-20 13:44:37 +08:00
|
|
|
local size = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
local kTagTileMap = 1
|
|
|
|
local kTagSpriteBatchNode = 1
|
|
|
|
local kTagNode = 2
|
|
|
|
local kTagAnimation1 = 1
|
|
|
|
local kTagSpriteLeft = 2
|
|
|
|
local kTagSpriteRight = 2
|
|
|
|
|
|
|
|
local kTagSprite1 = 0
|
|
|
|
local kTagSprite2 = 1
|
|
|
|
local kTagSprite3 = 2
|
|
|
|
local kTagSprite4 = 3
|
|
|
|
local kTagSprite5 = 4
|
|
|
|
local kTagSprite6 = 5
|
|
|
|
local kTagSprite7 = 6
|
|
|
|
local kTagSprite8 = 7
|
|
|
|
|
|
|
|
local testLayer = nil
|
|
|
|
local entry = nil
|
|
|
|
|
|
|
|
--------------------------------------------
|
|
|
|
---- test sprite1
|
|
|
|
--------------------------------------------
|
|
|
|
local Sprite1 = {}
|
|
|
|
Sprite1.__index = Sprite1
|
|
|
|
|
|
|
|
function Sprite1.addNewSpriteWithCoords(layer, point)
|
|
|
|
local idx = math.floor(math.random() * 1400 / 100)
|
|
|
|
local x = math.floor(math.mod(idx,5) * 85)
|
|
|
|
local y = math.floor(idx / 5 * 121)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(x,y,85,121) )
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild( sprite )
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setPosition( cc.p(point.x, point.y) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
local action = nil
|
|
|
|
local random = math.random()
|
|
|
|
cclog("random = " .. random)
|
|
|
|
if( random < 0.20 ) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.ScaleBy:create(3, 2)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif(random < 0.40) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.RotateBy:create(3, 360)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif( random < 0.60) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.Blink:create(1, 3)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif( random < 0.8 ) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.TintBy:create(2, 0, -255, -255)
|
2013-03-11 13:49:09 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.FadeOut:create(2)
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local action_back = action:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create( action, action_back)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:runAction( cc.RepeatForever:create(seq) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function Sprite1.onTouch(event, x, y)
|
|
|
|
if event == "began" then
|
|
|
|
return true
|
|
|
|
elseif event == "ended" then
|
2013-08-20 13:44:37 +08:00
|
|
|
Sprite1.addNewSpriteWithCoords(Helper.currentLayer, cc.p(x,y))
|
2013-03-11 13:49:09 +08:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Sprite1.create()
|
|
|
|
cclog("sprite1")
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
Sprite1.addNewSpriteWithCoords(layer, cc.p(size.width/2, size.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:setTouchEnabled(true)
|
|
|
|
layer:registerScriptTouchHandler(Sprite1.onTouch)
|
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite (tap screen)")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------
|
|
|
|
---- test SpriteBatchNode
|
|
|
|
--------------------------------------------
|
|
|
|
local SpriteBatchNode1 = {}
|
|
|
|
SpriteBatchNode1.__index = SpriteBatchNode1
|
|
|
|
|
|
|
|
function SpriteBatchNode1.addNewSpriteWithCoords(layer, point)
|
|
|
|
local BatchNode = layer:getChildByTag( kTagSpriteBatchNode )
|
|
|
|
local idx = math.floor(math.random() * 1400 / 100)
|
|
|
|
local x = math.floor(math.mod(idx,5) * 85)
|
|
|
|
local y = math.floor(idx / 5 * 121)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithTexture(BatchNode:getTexture(), cc.rect(x,y,85,121) )
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild( sprite )
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setPosition( cc.p(point.x, point.y) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
local action = nil
|
|
|
|
local random = math.random()
|
|
|
|
cclog("random = " .. random)
|
|
|
|
if( random < 0.20 ) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.ScaleBy:create(3, 2)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif(random < 0.40) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.RotateBy:create(3, 360)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif( random < 0.60) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.Blink:create(1, 3)
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif( random < 0.8 ) then
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.TintBy:create(2, 0, -255, -255)
|
2013-03-11 13:49:09 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
action = cc.FadeOut:create(2)
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local action_back = action:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create( action, action_back)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:runAction( cc.RepeatForever:create(seq) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNode1.onTouch(event, x, y)
|
|
|
|
if event == "began" then
|
|
|
|
return true
|
|
|
|
elseif event == "ended" then
|
2013-08-20 13:44:37 +08:00
|
|
|
SpriteBatchNode1.addNewSpriteWithCoords(Helper.currentLayer, cc.p(x,y))
|
2013-03-11 13:49:09 +08:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNode1.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local BatchNode = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 50)
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(BatchNode, 0, kTagSpriteBatchNode)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
SpriteBatchNode1.addNewSpriteWithCoords(layer, cc.p(size.width/2, size.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:setTouchEnabled(true)
|
|
|
|
layer:registerScriptTouchHandler(SpriteBatchNode1.onTouch)
|
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode (tap screen)")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------
|
|
|
|
---- SpriteColorOpacity
|
|
|
|
--------------------------------------
|
|
|
|
local SpriteColorOpacity = {}
|
|
|
|
SpriteColorOpacity.__index = SpriteColorOpacity
|
|
|
|
SpriteColorOpacity.entry = nil
|
|
|
|
|
|
|
|
function SpriteColorOpacity.setLayerSprite(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite1 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*0, 121*1, 85, 121))
|
|
|
|
local sprite2 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*1, 121*1, 85, 121))
|
|
|
|
local sprite3 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*2, 121*1, 85, 121))
|
|
|
|
local sprite4 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*3, 121*1, 85, 121))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite5 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*0, 121*1, 85, 121))
|
|
|
|
local sprite6 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*1, 121*1, 85, 121))
|
|
|
|
local sprite7 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*2, 121*1, 85, 121))
|
|
|
|
local sprite8 = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*3, 121*1, 85, 121))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
sprite1:setPosition( cc.p( (s.width/5)*1, (s.height/3)*1) )
|
|
|
|
sprite2:setPosition( cc.p( (s.width/5)*2, (s.height/3)*1) )
|
|
|
|
sprite3:setPosition( cc.p( (s.width/5)*3, (s.height/3)*1) )
|
|
|
|
sprite4:setPosition( cc.p( (s.width/5)*4, (s.height/3)*1) )
|
|
|
|
sprite5:setPosition( cc.p( (s.width/5)*1, (s.height/3)*2) )
|
|
|
|
sprite6:setPosition( cc.p( (s.width/5)*2, (s.height/3)*2) )
|
|
|
|
sprite7:setPosition( cc.p( (s.width/5)*3, (s.height/3)*2) )
|
|
|
|
sprite8:setPosition( cc.p( (s.width/5)*4, (s.height/3)*2) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local action = cc.FadeIn:create(2)
|
2013-03-11 13:49:09 +08:00
|
|
|
local action_back = action:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local fade = cc.RepeatForever:create( cc.Sequence:create( action, action_back) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local tintred = cc.TintBy:create(2, 0, -255, -255)
|
2013-03-11 13:49:09 +08:00
|
|
|
local tintred_back = tintred:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local red = cc.RepeatForever:create( cc.Sequence:create( tintred, tintred_back) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local tintgreen = cc.TintBy:create(2, -255, 0, -255)
|
2013-03-11 13:49:09 +08:00
|
|
|
local tintgreen_back = tintgreen:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local green = cc.RepeatForever:create( cc.Sequence:create( tintgreen, tintgreen_back) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local tintblue = cc.TintBy:create(2, -255, -255, 0)
|
2013-03-11 13:49:09 +08:00
|
|
|
local tintblue_back = tintblue:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local blue = cc.RepeatForever:create( cc.Sequence:create( tintblue, tintblue_back) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
sprite5:runAction(red)
|
|
|
|
sprite6:runAction(green)
|
|
|
|
sprite7:runAction(blue)
|
|
|
|
sprite8:runAction(fade)
|
|
|
|
|
|
|
|
layer:addChild(sprite1, 0, kTagSprite1)
|
|
|
|
layer:addChild(sprite2, 0, kTagSprite2)
|
|
|
|
layer:addChild(sprite3, 0, kTagSprite3)
|
|
|
|
layer:addChild(sprite4, 0, kTagSprite4)
|
|
|
|
layer:addChild(sprite5, 0, kTagSprite5)
|
|
|
|
layer:addChild(sprite6, 0, kTagSprite6)
|
|
|
|
layer:addChild(sprite7, 0, kTagSprite7)
|
|
|
|
layer:addChild(sprite8, 0, kTagSprite8)
|
|
|
|
|
|
|
|
layer:registerScriptHandler(SpriteColorOpacity.onEnterOrExit)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteColorOpacity.onEnterOrExit(tag)
|
|
|
|
if tag == "enter" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteColorOpacity.onEnter()
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif tag == "exit" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteColorOpacity.onExit()
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteColorOpacity.removeAndAddSprite(dt)
|
2013-03-13 17:45:09 +08:00
|
|
|
local sprite = Helper.currentLayer:getChildByTag(kTagSprite5)
|
2013-03-11 13:49:09 +08:00
|
|
|
sprite:retain()
|
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.currentLayer:removeChild(sprite, false)
|
|
|
|
Helper.currentLayer:addChild(sprite, 0, kTagSprite5)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
sprite:release()
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteColorOpacity.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
SpriteColorOpacity.setLayerSprite(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
layer:registerScriptHandler(SpriteColorOpacity.onEnterOrExit)
|
|
|
|
Helper.titleLabel:setString("Sprite: Color & Opacity")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------
|
|
|
|
---- SpriteFrameTest
|
|
|
|
--------------------------------------
|
|
|
|
local SpriteFrameTest = {}
|
|
|
|
SpriteFrameTest.__index = SpriteFrameTest
|
|
|
|
SpriteFrameTest.entry = nil
|
|
|
|
SpriteFrameTest.m_pSprite1 = nil
|
|
|
|
SpriteFrameTest.m_pSprite2 = nil
|
|
|
|
SpriteFrameTest.m_nCounter = 0
|
|
|
|
|
|
|
|
function SpriteFrameTest.onEnter()
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
|
|
|
cache:addSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
SpriteFrameTest.m_pSprite1 = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
SpriteFrameTest.m_pSprite1:setPosition( cc.p( s.width/2-80, s.height/2) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
spritebatch:addChild(SpriteFrameTest.m_pSprite1)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.currentLayer:addChild(spritebatch)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for i = 1,14 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame( string.format("grossini_dance_%02d.png", i) )
|
|
|
|
animFrames[i] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
SpriteFrameTest.m_pSprite1:runAction( cc.RepeatForever:create( cc.Animate:create(animation) ) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
SpriteFrameTest.m_pSprite1:setFlipX(false)
|
|
|
|
SpriteFrameTest.m_pSprite1:setFlipY(false)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
SpriteFrameTest.m_pSprite2 = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
SpriteFrameTest.m_pSprite2:setPosition( cc.p( s.width/2 + 80, s.height/2) )
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.currentLayer:addChild(SpriteFrameTest.m_pSprite2)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local moreFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for i = 1,14 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_gray_%02d.png",i))
|
|
|
|
moreFrames[i] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1,4 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_blue_%02d.png",i))
|
|
|
|
moreFrames[14 + i] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
--contact
|
|
|
|
for i = 1, 14 do
|
|
|
|
moreFrames[18 + i] = animFrames[i]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local animMixed = cc.Animation:createWithSpriteFrames(moreFrames, 0.3)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
SpriteFrameTest.m_pSprite2:runAction(cc.RepeatForever:create( cc.Animate:create(animMixed) ) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
SpriteFrameTest.m_pSprite2:setFlipX(false)
|
|
|
|
SpriteFrameTest.m_pSprite2:setFlipY(false)
|
|
|
|
|
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
performWithDelay(Helper.currentLayer,SpriteFrameTest.startIn05Secs, 0.5)
|
2013-03-11 13:49:09 +08:00
|
|
|
SpriteFrameTest.m_nCounter = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameTest.onExit()
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-11 13:49:09 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_blue.plist")
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameTest.startIn05Secs(dt)
|
2013-03-13 17:45:09 +08:00
|
|
|
schedule(Helper.currentLayer,SpriteFrameTest.flipSprites, 1)
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameTest.flipSprites(dt)
|
|
|
|
SpriteFrameTest.m_nCounter = SpriteFrameTest.m_nCounter + 1
|
|
|
|
|
|
|
|
local fx = false
|
|
|
|
local fy = false
|
|
|
|
local i = math.mod(SpriteFrameTest.m_nCounter, 4)
|
|
|
|
|
|
|
|
if(i == 0) then
|
|
|
|
fx = false
|
|
|
|
fy = false
|
|
|
|
elseif i == 1 then
|
|
|
|
fx = true
|
|
|
|
fy = false
|
|
|
|
elseif i == 2 then
|
|
|
|
fx = false
|
|
|
|
fy = true
|
|
|
|
elseif i == 3 then
|
|
|
|
fx = true
|
|
|
|
fy = true
|
|
|
|
end
|
|
|
|
|
|
|
|
SpriteFrameTest.m_pSprite1:setFlipX(fx)
|
|
|
|
SpriteFrameTest.m_pSprite1:setFlipY(fy)
|
|
|
|
SpriteFrameTest.m_pSprite2:setFlipX(fx)
|
|
|
|
SpriteFrameTest.m_pSprite2:setFlipY(fy)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function SpriteFrameTest.onEnterOrExit(tag)
|
|
|
|
if tag == "enter" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteFrameTest.onEnter()
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif tag == "exit" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteFrameTest.onExit()
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameTest.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:registerScriptHandler(SpriteFrameTest.onEnterOrExit)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite vs. SpriteBatchNode animation")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteFrameAliasNameTest
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteFrameAliasNameTest = {}
|
|
|
|
SpriteFrameAliasNameTest.__index = SpriteFrameAliasNameTest
|
|
|
|
|
|
|
|
function SpriteFrameAliasNameTest.onEnter()
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini-aliases.plist", "animations/grossini-aliases.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width * 0.5, s.height * 0.5))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spriteBatch = cc.SpriteBatchNode:create("animations/grossini-aliases.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
cclog("spriteBatch = " .. tostring(tolua.isnull(spriteBatch)))
|
|
|
|
cclog("sprite = " .. tostring(tolua.isnull(sprite)))
|
|
|
|
spriteBatch:addChild(sprite)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.currentLayer:addChild(spriteBatch)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for i = 1,14 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("dance_%02d", i))
|
|
|
|
animFrames[i] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
2013-03-11 13:49:09 +08:00
|
|
|
-- 14 frames * 1sec = 14 seconds
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameAliasNameTest.onExit()
|
2013-08-20 13:44:37 +08:00
|
|
|
cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile("animations/grossini-aliases.plist")
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameAliasNameTest.onEnterOrExit(tag)
|
|
|
|
if tag == "enter" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteFrameAliasNameTest.onEnter()
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif tag == "exit" then
|
2013-03-13 17:45:09 +08:00
|
|
|
SpriteFrameAliasNameTest.onExit()
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteFrameAliasNameTest.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:registerScriptHandler(SpriteFrameAliasNameTest.onEnterOrExit)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteFrame Alias Name")
|
|
|
|
Helper.subtitleLabel:setString("SpriteFrames are obtained using the alias name")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteAnchorPoint
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteAnchorPoint = {}
|
|
|
|
SpriteAnchorPoint.__index = SpriteAnchorPoint
|
|
|
|
|
|
|
|
function SpriteAnchorPoint.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local rotate = cc.RotateBy:create(10, 360)
|
|
|
|
local action = cc.RepeatForever:create(rotate)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:create("Images/grossini_dance_atlas.png", cc.rect(85*i, 121*1, 85, 121) )
|
|
|
|
sprite:setPosition( cc.p( s.width/4*(i+1), s.height/2) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale( 0.25 )
|
|
|
|
point:setPosition( sprite:getPosition() )
|
|
|
|
layer:addChild(point, 10)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0, 0) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0.5, 0.5) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(1,1) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
point:setPosition( sprite:getPosition() )
|
|
|
|
|
2014-01-15 23:31:00 +08:00
|
|
|
local copy = tolua.cast(action:clone(), "cc.Action")
|
2013-03-11 13:49:09 +08:00
|
|
|
sprite:runAction(copy)
|
|
|
|
layer:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteAnchorPoint.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteAnchorPoint.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite: anchor point")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
-- SpriteBatchNodeAnchorPoint
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteBatchNodeAnchorPoint = {}
|
|
|
|
SpriteBatchNodeAnchorPoint.__index = SpriteBatchNodeAnchorPoint
|
|
|
|
|
|
|
|
function SpriteBatchNodeAnchorPoint.initLayer(layer)
|
|
|
|
-- small capacity. Testing resizing.
|
|
|
|
-- Don't use capacity=1 in your real game. It is expensive to resize the capacity
|
2013-08-20 13:44:37 +08:00
|
|
|
local batch = cc.SpriteBatchNode:create("Images/grossini_dance_atlas.png", 1)
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(batch, 0, kTagSpriteBatchNode)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local rotate = cc.RotateBy:create(10, 360)
|
|
|
|
local action = cc.RepeatForever:create(rotate)
|
2013-03-11 13:49:09 +08:00
|
|
|
for i=0,2 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithTexture(batch:getTexture(), cc.rect(85*i, 121*1, 85, 121))
|
|
|
|
sprite:setPosition( cc.p( s.width/4*(i+1), s.height/2) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale( 0.25 )
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0,0) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0.5, 0.5) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(1,1) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2014-01-15 23:31:00 +08:00
|
|
|
local copy = tolua.cast(action:clone(), "cc.Action")
|
2013-03-11 13:49:09 +08:00
|
|
|
sprite:runAction(copy)
|
|
|
|
batch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeAnchorPoint.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteBatchNodeAnchorPoint.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode: anchor point")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorRotation
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteOffsetAnchorRotation = {}
|
|
|
|
SpriteOffsetAnchorRotation.__index = SpriteOffsetAnchorRotation
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorRotation.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i=0,2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p( s.width/4*(i+1), s.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale( 0.25 )
|
|
|
|
point:setPosition( sprite:getPosition() )
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0, 0) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0.5, 0.5) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(1,1) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png",(i+1)))
|
|
|
|
animFrames[i + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create( cc.Animate:create(animation) ) )
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.RotateBy:create(10, 360) ) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 14:35:33 +08:00
|
|
|
function SpriteOffsetAnchorRotation.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 14:35:33 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteOffsetAnchorRotation.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 14:35:33 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorRotation.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorRotation.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite offset + anchor + rot")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteBatchNodeOffsetAnchorRotation
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteBatchNodeOffsetAnchorRotation = {}
|
|
|
|
SpriteBatchNodeOffsetAnchorRotation.__index = SpriteBatchNodeOffsetAnchorRotation
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotation.initLayer(layer)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
cclog("1")
|
|
|
|
layer:addChild(spritebatch)
|
|
|
|
|
|
|
|
cclog("2")
|
|
|
|
for i = 0,2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite BatchNode
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition( cc.p( s.width/4*(i+1), s.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale( 0.25 )
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0,0) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0.5, 0.5) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(1,1) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for k = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png",(k+1)))
|
|
|
|
animFrames[k + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create( cc.Animate:create(animation) ))
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.RotateBy:create(10, 360) ))
|
2013-03-11 13:49:09 +08:00
|
|
|
spritebatch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
function SpriteBatchNodeOffsetAnchorRotation.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteBatchNodeOffsetAnchorRotation.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotation.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteBatchNodeOffsetAnchorRotation.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode offset + anchor + rot")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorScale
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
local SpriteOffsetAnchorScale = {}
|
|
|
|
SpriteOffsetAnchorScale.__index = SpriteOffsetAnchorScale
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0,2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite BatchNode
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition( cc.p( s.width/4*(i+1), s.height/2) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale( 0.25 )
|
|
|
|
point:setPosition( sprite:getPosition() )
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0, 0) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(0.5, 0.5) )
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint( cc.p(1,1) )
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition( cc.p(sprite:getPosition()) )
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png",(i+1)))
|
|
|
|
animFrames[i + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create( cc.Animate:create(animation) ))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-11 13:49:09 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
function SpriteOffsetAnchorScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteOffsetAnchorScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorScale.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorScale.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite offset + anchor + scale")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteBatchNodeOffsetAnchorScale
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
2013-03-12 18:21:34 +08:00
|
|
|
local SpriteBatchNodeOffsetAnchorScale = {}
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-12 18:21:34 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-12 18:21:34 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritesheet = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-12 18:21:34 +08:00
|
|
|
layer:addChild(spritesheet)
|
|
|
|
|
|
|
|
for i = 0,2 do
|
|
|
|
-- Animation using Sprite BatchNode
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width/4*(i+1), s.height/2))
|
2013-03-12 18:21:34 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-12 18:21:34 +08:00
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0,0))
|
2013-03-12 18:21:34 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-12 18:21:34 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-12 18:21:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-12 18:21:34 +08:00
|
|
|
local str
|
|
|
|
for k = 0, 13 do
|
|
|
|
str = string.format("grossini_dance_%02d.png", (k+1))
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(str)
|
|
|
|
animFrames[k + 1] = frame
|
2013-03-12 18:21:34 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-12 18:21:34 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-12 18:21:34 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-12 18:21:34 +08:00
|
|
|
|
|
|
|
spritesheet:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorScale.onExit()
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-12 18:21:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
|
|
|
SpriteBatchNodeOffsetAnchorScale.onExit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-12 18:21:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorScale.eventHandler)
|
|
|
|
|
|
|
|
layer = SpriteBatchNodeOffsetAnchorScale.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-12 18:21:34 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorSkew
|
|
|
|
--
|
|
|
|
--------------------------------------------------------------------
|
2013-03-11 13:49:09 +08:00
|
|
|
local SpriteOffsetAnchorSkew = {}
|
|
|
|
SpriteOffsetAnchorSkew.__index = SpriteOffsetAnchorSkew
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorSkew.initLayer(layer)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", j + 1))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.SkewBy:create(2, 45, 0)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.SkewBy:create(2, 0, 45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
function SpriteOffsetAnchorSkew.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
function SpriteOffsetAnchorSkew.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorSkew.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorSkew.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode offset + anchor + scale")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
------------------------------------------------------------
|
|
|
|
-- SpriteOffsetAnchorRotationalSkew
|
|
|
|
------------------------------------------------------------
|
|
|
|
local SpriteOffsetAnchorRotationalSkew = {}
|
|
|
|
SpriteOffsetAnchorRotationalSkew.__index = SpriteOffsetAnchorRotationalSkew
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorRotationalSkew.initLayer(layer)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width/4*(i+1), s.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
point:setScale(0.25)
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0,0))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1,1))
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for i = 0,13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", (i+1)))
|
|
|
|
animFrames[i + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.RotateBy:create(2, 45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.RotateBy:create(2, -45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
function SpriteOffsetAnchorRotationalSkew.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteOffsetAnchorRotationalSkew.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorRotationalSkew.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorRotationalSkew.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("Sprite offset + anchor + rotational skew")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------
|
2013-03-14 11:53:34 +08:00
|
|
|
-- SpriteBatchNodeOffsetAnchorSkew
|
2013-03-11 13:49:09 +08:00
|
|
|
------------------------------------------------------------
|
|
|
|
local SpriteBatchNodeOffsetAnchorSkew = {}
|
|
|
|
SpriteBatchNodeOffsetAnchorSkew.__index = SpriteBatchNodeOffsetAnchorSkew
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorSkew.initLayer(layer)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(spritebatch)
|
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
point:setScale(0.25)
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", j + 1))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.SkewBy:create(2, 45, 0)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.SkewBy:create(2, 0, 45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
spritebatch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
function SpriteBatchNodeOffsetAnchorSkew.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteBatchNodeOffsetAnchorSkew.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorSkew.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteBatchNodeOffsetAnchorSkew.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SpriteBatchNode offset + anchor + skew")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
-- SpriteBatchNodeOffsetAnchorRotationalSkew
|
|
|
|
--
|
|
|
|
local SpriteBatchNodeOffsetAnchorRotationalSkew = {}
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkew.__index = SpriteBatchNodeOffsetAnchorRotationalSkew
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer)
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(spritebatch)
|
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
--
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
--
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width/4*(i+1), s.height/2))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
point:setScale(0.25)
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0,0))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-11 13:49:09 +08:00
|
|
|
elseif i == 2 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1,1))
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
point:setPosition(cc.p(sprite:getPosition()))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-11 13:49:09 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", (j+1)))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-11 13:49:09 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.RotateBy:create(2, 45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.RotateBy:create(2, -45)
|
2013-03-11 13:49:09 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
spritebatch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
-- remove resources
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkew.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 11:53:34 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkew.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 11:53:34 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotationalSkew.eventHandler)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.initWithLayer(layer)
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
layer = SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer)
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.titleLabel:setString("SSpriteBatchNode offset + anchor + rot skew")
|
|
|
|
Helper.subtitleLabel:setString("")
|
2013-03-11 13:49:09 +08:00
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 11:53:34 +08:00
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorSkewScale
|
|
|
|
--
|
2013-03-14 14:35:33 +08:00
|
|
|
local SpriteOffsetAnchorSkewScale = {}
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorSkewScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-14 14:35:33 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-14 14:35:33 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
-- Animation using Sprite batch
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
|
2013-03-14 14:35:33 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-14 14:35:33 +08:00
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0,0))
|
2013-03-14 14:35:33 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-14 14:35:33 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-14 14:35:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-14 14:35:33 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", j+1))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-14 14:35:33 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-14 14:35:33 +08:00
|
|
|
|
|
|
|
-- Skew
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.SkewBy:create(2, 45, 0)
|
2013-03-14 14:35:33 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.SkewBy:create(2, 0, 45)
|
2013-03-14 14:35:33 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-14 14:35:33 +08:00
|
|
|
|
|
|
|
-- Scale
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-14 14:35:33 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-14 14:35:33 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorSkewScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 14:35:33 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorSkewScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 14:35:33 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorSkewScale.eventHandler)
|
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorSkewScale.initLayer(layer)
|
|
|
|
Helper.titleLabel:setString("Sprite anchor + skew + scale")
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
2013-03-14 11:53:34 +08:00
|
|
|
|
2013-03-14 15:11:55 +08:00
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorRotationalSkewScale
|
|
|
|
--
|
|
|
|
local SpriteOffsetAnchorRotationalSkewScale = {}
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorRotationalSkewScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-14 15:11:55 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-14 15:11:55 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
-- Animation using Sprite batch
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width/4*(i+1), s.height/2))
|
2013-03-14 15:11:55 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-14 15:11:55 +08:00
|
|
|
|
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-14 15:11:55 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-14 15:11:55 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-14 15:11:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-14 15:11:55 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", (j+1)))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-14 15:11:55 +08:00
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-14 15:11:55 +08:00
|
|
|
|
|
|
|
-- Skew
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.RotateBy:create(2, 45, 0)
|
2013-03-14 15:11:55 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.RotateBy:create(2, 0, 45)
|
2013-03-14 15:11:55 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-14 15:11:55 +08:00
|
|
|
|
|
|
|
-- Scale
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-14 15:11:55 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-14 15:11:55 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorRotationalSkewScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 15:11:55 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorRotationalSkewScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 15:11:55 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorRotationalSkewScale.eventHandler)
|
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
|
|
|
|
layer = SpriteOffsetAnchorRotationalSkewScale.initLayer(layer)
|
|
|
|
Helper.titleLabel:setString("Sprite anchor + rot skew + scale")
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 15:49:20 +08:00
|
|
|
--
|
|
|
|
-- SpriteBatchNodeOffsetAnchorSkewScale
|
|
|
|
--
|
|
|
|
local SpriteBatchNodeOffsetAnchorSkewScale = {}
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorSkewScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-14 15:49:20 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-14 15:49:20 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-14 15:49:20 +08:00
|
|
|
layer:addChild(spritebatch)
|
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
-- Animation using Sprite batch
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
|
2013-03-14 15:49:20 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-14 15:49:20 +08:00
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-14 15:49:20 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-14 15:49:20 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-14 15:49:20 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-14 15:49:20 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", (j+1)))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-14 15:49:20 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-14 15:49:20 +08:00
|
|
|
|
|
|
|
-- skew
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.SkewBy:create(2, 45, 0)
|
2013-03-14 15:49:20 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.SkewBy:create(2, 0, 45)
|
2013-03-14 15:49:20 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-14 15:49:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
-- scale
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-14 15:49:20 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-14 15:49:20 +08:00
|
|
|
|
|
|
|
spritebatch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorSkewScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 15:49:20 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorSkewScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 15:49:20 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorSkewScale.eventHandler)
|
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
|
|
|
|
SpriteBatchNodeOffsetAnchorSkewScale.initLayer(layer)
|
|
|
|
Helper.titleLabel:setString("SpriteBatchNode anchor + skew + scale")
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 17:45:21 +08:00
|
|
|
--
|
|
|
|
-- SpriteBatchNodeOffsetAnchorRotationalSkewScale
|
|
|
|
--
|
|
|
|
local SpriteBatchNodeOffsetAnchorRotationalSkewScale = {}
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-14 17:45:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-14 17:45:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local spritebatch = cc.SpriteBatchNode:create("animations/grossini.png")
|
2013-03-14 17:45:21 +08:00
|
|
|
layer:addChild(spritebatch)
|
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
-- Animation using Sprite batch
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width/4*(i+1), s.height/2))
|
2013-03-14 17:45:21 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-14 17:45:21 +08:00
|
|
|
|
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
|
|
|
layer:addChild(point, 200)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-14 17:45:21 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-14 17:45:21 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-14 17:45:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-14 17:45:21 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", j+1))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-14 17:45:21 +08:00
|
|
|
end
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-14 17:45:21 +08:00
|
|
|
|
|
|
|
-- Skew
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewX = cc.RotateBy:create(2, 45, 0)
|
2013-03-14 17:45:21 +08:00
|
|
|
local skewX_back = skewX:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local skewY = cc.RotateBy:create(2, 0, 45)
|
2013-03-14 17:45:21 +08:00
|
|
|
local skewY_back = skewY:reverse()
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_skew = cc.Sequence:create(skewX, skewX_back, skewY, skewY_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_skew))
|
2013-03-14 17:45:21 +08:00
|
|
|
|
|
|
|
-- Scale
|
2013-08-20 13:44:37 +08:00
|
|
|
local scale = cc.ScaleBy:create(2, 2)
|
2013-03-14 17:45:21 +08:00
|
|
|
local scale_back = scale:reverse()
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq_scale = cc.Sequence:create(scale, scale_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq_scale))
|
2013-03-14 17:45:21 +08:00
|
|
|
|
|
|
|
spritebatch:addChild(sprite, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 17:45:21 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 17:45:21 +08:00
|
|
|
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotationalSkewScale.eventHandler)
|
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkewScale.initLayer(layer)
|
|
|
|
|
|
|
|
Helper.titleLabel:setString("SpriteBatchNode anchor + rot skew + scale")
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 18:14:01 +08:00
|
|
|
--
|
|
|
|
-- SpriteOffsetAnchorFlip
|
|
|
|
--
|
|
|
|
local SpriteOffsetAnchorFlip = {}
|
|
|
|
function SpriteOffsetAnchorFlip.initLayer(layer)
|
2013-08-20 13:44:37 +08:00
|
|
|
local s = cc.Director:getInstance():getWinSize()
|
2013-03-14 18:14:01 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
|
|
|
cache:addSpriteFrames("animations/grossini.plist")
|
|
|
|
cache:addSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
2013-03-14 18:14:01 +08:00
|
|
|
|
|
|
|
for i = 0, 2 do
|
|
|
|
-- Animation using Sprite batch
|
2013-08-20 13:44:37 +08:00
|
|
|
local sprite = cc.Sprite:createWithSpriteFrameName("grossini_dance_01.png")
|
|
|
|
sprite:setPosition(cc.p(s.width / 4 * (i + 1), s.height / 2))
|
2013-03-14 18:14:01 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local point = cc.Sprite:create("Images/r1.png")
|
2013-03-14 18:14:01 +08:00
|
|
|
point:setScale(0.25)
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
layer:addChild(point, 1)
|
|
|
|
|
|
|
|
if i == 0 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0, 0))
|
2013-03-14 18:14:01 +08:00
|
|
|
elseif i == 1 then
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(0.5, 0.5))
|
2013-03-14 18:14:01 +08:00
|
|
|
else
|
2013-08-20 13:44:37 +08:00
|
|
|
sprite:setAnchorPoint(cc.p(1, 1))
|
2013-03-14 18:14:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
point:setPosition(sprite:getPosition())
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animFrames = {}
|
2013-03-14 18:14:01 +08:00
|
|
|
for j = 0, 13 do
|
2013-08-20 13:44:37 +08:00
|
|
|
local frame = cache:getSpriteFrame(string.format("grossini_dance_%02d.png", j+1))
|
|
|
|
animFrames[j + 1] = frame
|
2013-03-14 18:14:01 +08:00
|
|
|
end
|
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local animation = cc.Animation:createWithSpriteFrames(animFrames, 0.3)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(cc.Animate:create(animation)))
|
2013-03-14 18:14:01 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local flip = cc.FlipY:create(true)
|
|
|
|
local flip_back = cc.FlipY:create(false)
|
|
|
|
local delay = cc.DelayTime:create(1)
|
|
|
|
local delay2 = cc.DelayTime:create(1)
|
2013-03-14 18:14:01 +08:00
|
|
|
|
2013-08-20 13:44:37 +08:00
|
|
|
local seq = cc.Sequence:create(delay, flip, delay2, flip_back)
|
|
|
|
sprite:runAction(cc.RepeatForever:create(seq))
|
2013-03-14 18:14:01 +08:00
|
|
|
|
|
|
|
layer:addChild(sprite, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorFlip.eventHandler(tag)
|
|
|
|
if tag == "exit" then
|
2013-08-20 13:44:37 +08:00
|
|
|
local cache = cc.SpriteFrameCache:getInstance()
|
2013-03-14 18:14:01 +08:00
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
|
|
|
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SpriteOffsetAnchorFlip.create()
|
2013-08-20 13:44:37 +08:00
|
|
|
local layer = cc.Layer:create()
|
2013-03-14 18:14:01 +08:00
|
|
|
layer:registerScriptHandler(SpriteOffsetAnchorFlip.eventHandler)
|
|
|
|
Helper.initWithLayer(layer)
|
|
|
|
|
|
|
|
SpriteOffsetAnchorFlip.initLayer(layer)
|
|
|
|
Helper.titleLabel:setString("Sprite offset + anchor + flip")
|
|
|
|
Helper.subtitleLabel:setString("issue #1078")
|
|
|
|
|
|
|
|
return layer
|
|
|
|
end
|
|
|
|
|
2013-03-14 15:11:55 +08:00
|
|
|
|
2013-03-11 13:49:09 +08:00
|
|
|
function SpriteTest()
|
2013-08-20 13:44:37 +08:00
|
|
|
local scene = cc.Scene:create()
|
2013-03-12 18:21:34 +08:00
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
Helper.createFunctionTable = {
|
2013-03-12 18:21:34 +08:00
|
|
|
Sprite1.create,
|
|
|
|
SpriteBatchNode1.create,
|
|
|
|
SpriteFrameTest.create,
|
|
|
|
SpriteFrameAliasNameTest.create,
|
|
|
|
SpriteAnchorPoint.create,
|
|
|
|
SpriteBatchNodeAnchorPoint.create,
|
|
|
|
SpriteOffsetAnchorRotation.create,
|
|
|
|
SpriteBatchNodeOffsetAnchorRotation.create,
|
|
|
|
SpriteOffsetAnchorScale.create,
|
|
|
|
SpriteBatchNodeOffsetAnchorScale.create,
|
|
|
|
SpriteOffsetAnchorSkew.create,
|
|
|
|
SpriteOffsetAnchorRotationalSkew.create,
|
|
|
|
SpriteBatchNodeOffsetAnchorSkew.create,
|
2013-03-14 14:35:33 +08:00
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkew.create,
|
2013-03-14 15:11:55 +08:00
|
|
|
SpriteOffsetAnchorSkewScale.create,
|
2013-03-14 15:49:20 +08:00
|
|
|
SpriteOffsetAnchorRotationalSkewScale.create,
|
2013-03-14 17:45:21 +08:00
|
|
|
SpriteBatchNodeOffsetAnchorSkewScale.create,
|
2013-03-14 18:14:01 +08:00
|
|
|
SpriteBatchNodeOffsetAnchorRotationalSkewScale.create,
|
|
|
|
SpriteOffsetAnchorFlip.create
|
2013-03-12 18:21:34 +08:00
|
|
|
}
|
|
|
|
|
2013-03-13 17:45:09 +08:00
|
|
|
scene:addChild(Sprite1.create())
|
2013-03-11 13:49:09 +08:00
|
|
|
scene:addChild(CreateBackMenuItem())
|
|
|
|
|
|
|
|
return scene
|
|
|
|
end
|