mirror of https://github.com/axmolengine/axmol.git
Merge pull request #2163 from minggo/iss1803-spritetest-lua
add some lua test cases
This commit is contained in:
commit
f80318cc8d
|
@ -565,8 +565,17 @@ function SpriteOffsetAnchorRotation.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotation.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotation.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorRotation.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorRotation.initLayer(layer)
|
||||
|
@ -634,8 +643,17 @@ function SpriteBatchNodeOffsetAnchorRotation.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorRotation.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorRotation.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotation.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteBatchNodeOffsetAnchorRotation.initLayer(layer)
|
||||
|
@ -703,8 +721,17 @@ function SpriteOffsetAnchorScale.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorScale.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorScale.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorScale.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorScale.initLayer(layer)
|
||||
|
@ -863,9 +890,17 @@ function SpriteOffsetAnchorSkew.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorSkew.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorSkew.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorSkew.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorSkew.initLayer(layer)
|
||||
|
@ -937,8 +972,17 @@ function SpriteOffsetAnchorRotationalSkew.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotationalSkew.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotationalSkew.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorRotationalSkew.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorRotationalSkew.initLayer(layer)
|
||||
|
@ -950,7 +994,7 @@ end
|
|||
|
||||
|
||||
------------------------------------------------------------
|
||||
-- SpriteOffsetAnchorRotationalSkew
|
||||
-- SpriteBatchNodeOffsetAnchorSkew
|
||||
------------------------------------------------------------
|
||||
local SpriteBatchNodeOffsetAnchorSkew = {}
|
||||
SpriteBatchNodeOffsetAnchorSkew.__index = SpriteBatchNodeOffsetAnchorSkew
|
||||
|
@ -1016,8 +1060,17 @@ function SpriteBatchNodeOffsetAnchorSkew.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorSkew.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorSkew.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorSkew.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteBatchNodeOffsetAnchorSkew.initLayer(layer)
|
||||
|
@ -1095,8 +1148,18 @@ function SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer)
|
|||
return layer
|
||||
end
|
||||
|
||||
-- remove resources
|
||||
function SpriteBatchNodeOffsetAnchorRotationalSkew.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorRotationalSkew.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotationalSkew.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer)
|
||||
|
@ -1106,6 +1169,432 @@ function SpriteBatchNodeOffsetAnchorRotationalSkew.create()
|
|||
return layer
|
||||
end
|
||||
|
||||
--
|
||||
-- SpriteOffsetAnchorSkewScale
|
||||
--
|
||||
local SpriteOffsetAnchorSkewScale = {}
|
||||
|
||||
function SpriteOffsetAnchorSkewScale.initLayer(layer)
|
||||
local s = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:addSpriteFramesWithFile("animations/grossini.plist")
|
||||
cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
||||
|
||||
for i = 0, 2 do
|
||||
-- Animation using Sprite batch
|
||||
local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
|
||||
sprite:setPosition(ccp(s.width / 4 * (i + 1), s.height / 2))
|
||||
|
||||
local point = CCSprite:create("Images/r1.png")
|
||||
point:setScale(0.25)
|
||||
point:setPosition(sprite:getPosition())
|
||||
layer:addChild(point, 1)
|
||||
|
||||
if i == 0 then
|
||||
sprite:setAnchorPoint(ccp(0,0))
|
||||
elseif i == 1 then
|
||||
sprite:setAnchorPoint(ccp(0.5, 0.5))
|
||||
else
|
||||
sprite:setAnchorPoint(ccp(1, 1))
|
||||
end
|
||||
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
local animFrames = CCArray:create()
|
||||
for j = 0, 13 do
|
||||
local frame = cache:spriteFrameByName(string.format("grossini_dance_%02d.png", j+1))
|
||||
animFrames:addObject(frame)
|
||||
end
|
||||
|
||||
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
|
||||
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
|
||||
|
||||
-- Skew
|
||||
local skewX = CCSkewBy:create(2, 45, 0)
|
||||
local skewX_back = skewX:reverse()
|
||||
local skewY = CCSkewBy:create(2, 0, 45)
|
||||
local skewY_back = skewY:reverse()
|
||||
|
||||
local actionArray = CCArray:create()
|
||||
actionArray:addObject(skewX)
|
||||
actionArray:addObject(skewX_back)
|
||||
actionArray:addObject(skewY)
|
||||
actionArray:addObject(skewY_back)
|
||||
local seq_skew = CCSequence:create(actionArray)
|
||||
sprite:runAction(CCRepeatForever:create(seq_skew))
|
||||
|
||||
-- Scale
|
||||
local scale = CCScaleBy:create(2, 2)
|
||||
local scale_back = scale:reverse()
|
||||
local seq_scale = CCSequence:createWithTwoActions(scale, scale_back)
|
||||
sprite:runAction(CCRepeatForever:create(seq_scale))
|
||||
|
||||
layer:addChild(sprite, 0)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorSkewScale.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorSkewScale.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorSkewScale.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorSkewScale.initLayer(layer)
|
||||
Helper.titleLabel:setString("Sprite anchor + skew + scale")
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--
|
||||
-- SpriteOffsetAnchorRotationalSkewScale
|
||||
--
|
||||
local SpriteOffsetAnchorRotationalSkewScale = {}
|
||||
|
||||
function SpriteOffsetAnchorRotationalSkewScale.initLayer(layer)
|
||||
local s = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:addSpriteFramesWithFile("animations/grossini.plist")
|
||||
cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
||||
|
||||
for i = 0, 2 do
|
||||
-- Animation using Sprite batch
|
||||
local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
|
||||
sprite:setPosition(ccp(s.width/4*(i+1), s.height/2))
|
||||
|
||||
local point = CCSprite:create("Images/r1.png")
|
||||
|
||||
point:setScale(0.25)
|
||||
point:setPosition(sprite:getPosition())
|
||||
layer:addChild(point, 1)
|
||||
|
||||
if i == 0 then
|
||||
sprite:setAnchorPoint(ccp(0, 0))
|
||||
elseif i == 1 then
|
||||
sprite:setAnchorPoint(ccp(0.5, 0.5))
|
||||
else
|
||||
sprite:setAnchorPoint(ccp(1, 1))
|
||||
end
|
||||
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
local animFrames = CCArray:create()
|
||||
for j = 0, 13 do
|
||||
local frame = cache:spriteFrameByName(string.format("grossini_dance_%02d.png", (j+1)))
|
||||
animFrames:addObject(frame)
|
||||
end
|
||||
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
|
||||
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
|
||||
|
||||
-- Skew
|
||||
local skewX = CCRotateBy:create(2, 45, 0)
|
||||
local skewX_back = skewX:reverse()
|
||||
local skewY = CCRotateBy:create(2, 0, 45)
|
||||
local skewY_back = skewY:reverse()
|
||||
|
||||
local actionArray = CCArray:create()
|
||||
actionArray:addObject(skewX)
|
||||
actionArray:addObject(skewX_back)
|
||||
actionArray:addObject(skewY)
|
||||
actionArray:addObject(skewY_back)
|
||||
local seq_skew = CCSequence:create(actionArray)
|
||||
sprite:runAction(CCRepeatForever:create(seq_skew))
|
||||
|
||||
-- Scale
|
||||
local scale = CCScaleBy:create(2, 2)
|
||||
local scale_back = scale:reverse()
|
||||
local seq_scale = CCSequence:createWithTwoActions(scale, scale_back)
|
||||
sprite:runAction(CCRepeatForever:create(seq_scale))
|
||||
|
||||
layer:addChild(sprite, i)
|
||||
end
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotationalSkewScale.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorRotationalSkewScale.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteOffsetAnchorRotationalSkewScale.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer = SpriteOffsetAnchorRotationalSkewScale.initLayer(layer)
|
||||
Helper.titleLabel:setString("Sprite anchor + rot skew + scale")
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--
|
||||
-- SpriteBatchNodeOffsetAnchorSkewScale
|
||||
--
|
||||
local SpriteBatchNodeOffsetAnchorSkewScale = {}
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorSkewScale.initLayer(layer)
|
||||
local s = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:addSpriteFramesWithFile("animations/grossini.plist")
|
||||
cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
||||
|
||||
local spritebatch = CCSpriteBatchNode:create("animations/grossini.png")
|
||||
layer:addChild(spritebatch)
|
||||
|
||||
for i = 0, 2 do
|
||||
-- Animation using Sprite batch
|
||||
|
||||
local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
|
||||
sprite:setPosition(ccp(s.width / 4 * (i + 1), s.height / 2))
|
||||
|
||||
local point = CCSprite:create("Images/r1.png")
|
||||
point:setScale(0.25)
|
||||
point:setPosition(sprite:getPosition())
|
||||
layer:addChild(point, 200)
|
||||
|
||||
if i == 0 then
|
||||
sprite:setAnchorPoint(ccp(0, 0))
|
||||
elseif i == 1 then
|
||||
sprite:setAnchorPoint(ccp(0.5, 0.5))
|
||||
else
|
||||
sprite:setAnchorPoint(ccp(1, 1))
|
||||
end
|
||||
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
local animFrames = CCArray:create()
|
||||
for j = 0, 13 do
|
||||
local frame = cache:spriteFrameByName(string.format("grossini_dance_%02d.png", (j+1)))
|
||||
animFrames:addObject(frame)
|
||||
end
|
||||
|
||||
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
|
||||
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
|
||||
|
||||
-- skew
|
||||
local skewX = CCSkewBy:create(2, 45, 0)
|
||||
local skewX_back = skewX:reverse()
|
||||
local skewY = CCSkewBy:create(2, 0, 45)
|
||||
local skewY_back = skewY:reverse()
|
||||
|
||||
local actionArray = CCArray:create()
|
||||
actionArray:addObject(skewX)
|
||||
actionArray:addObject(skewX_back)
|
||||
actionArray:addObject(skewY)
|
||||
actionArray:addObject(skewY_back)
|
||||
local seq_skew = CCSequence:create(actionArray)
|
||||
sprite:runAction(CCRepeatForever:create(seq_skew))
|
||||
|
||||
|
||||
-- scale
|
||||
local scale = CCScaleBy:create(2, 2)
|
||||
local scale_back = scale:reverse()
|
||||
local seq_scale = CCSequence:createWithTwoActions(scale, scale_back)
|
||||
sprite:runAction(CCRepeatForever:create(seq_scale))
|
||||
|
||||
spritebatch:addChild(sprite, i)
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorSkewScale.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorSkewScale.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorSkewScale.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
SpriteBatchNodeOffsetAnchorSkewScale.initLayer(layer)
|
||||
Helper.titleLabel:setString("SpriteBatchNode anchor + skew + scale")
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--
|
||||
-- SpriteBatchNodeOffsetAnchorRotationalSkewScale
|
||||
--
|
||||
local SpriteBatchNodeOffsetAnchorRotationalSkewScale = {}
|
||||
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.initLayer(layer)
|
||||
local s = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:addSpriteFramesWithFile("animations/grossini.plist")
|
||||
cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
||||
|
||||
local spritebatch = CCSpriteBatchNode:create("animations/grossini.png")
|
||||
layer:addChild(spritebatch)
|
||||
|
||||
for i = 0, 2 do
|
||||
-- Animation using Sprite batch
|
||||
local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
|
||||
sprite:setPosition(ccp(s.width/4*(i+1), s.height/2))
|
||||
|
||||
local point = CCSprite:create("Images/r1.png")
|
||||
|
||||
point:setScale(0.25)
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
layer:addChild(point, 200)
|
||||
|
||||
if i == 0 then
|
||||
sprite:setAnchorPoint(ccp(0, 0))
|
||||
elseif i == 1 then
|
||||
sprite:setAnchorPoint(ccp(0.5, 0.5))
|
||||
else
|
||||
sprite:setAnchorPoint(ccp(1, 1))
|
||||
end
|
||||
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
local animFrames = CCArray:create()
|
||||
for j = 0, 13 do
|
||||
local frame = cache:spriteFrameByName(string.format("grossini_dance_%02d.png", j+1))
|
||||
animFrames:addObject(frame)
|
||||
end
|
||||
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
|
||||
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
|
||||
|
||||
-- Skew
|
||||
local skewX = CCRotateBy:create(2, 45, 0)
|
||||
local skewX_back = skewX:reverse()
|
||||
local skewY = CCRotateBy:create(2, 0, 45)
|
||||
local skewY_back = skewY:reverse()
|
||||
|
||||
local actionArray = CCArray:create()
|
||||
actionArray:addObject(skewX)
|
||||
actionArray:addObject(skewX_back)
|
||||
actionArray:addObject(skewY)
|
||||
actionArray:addObject(skewY_back)
|
||||
local seq_skew = CCSequence:create(actionArray)
|
||||
sprite:runAction(CCRepeatForever:create(seq_skew))
|
||||
|
||||
-- Scale
|
||||
local scale = CCScaleBy:create(2, 2)
|
||||
local scale_back = scale:reverse()
|
||||
local seq_scale = CCSequence:createWithTwoActions(scale, scale_back)
|
||||
sprite:runAction(CCRepeatForever:create(seq_scale))
|
||||
|
||||
spritebatch:addChild(sprite, i)
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteBatchNodeOffsetAnchorRotationalSkewScale.create()
|
||||
local layer = CCLayer:create()
|
||||
layer:registerScriptHandler(SpriteBatchNodeOffsetAnchorRotationalSkewScale.eventHandler)
|
||||
Helper.initWithLayer(layer)
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkewScale.initLayer(layer)
|
||||
|
||||
Helper.titleLabel:setString("SpriteBatchNode anchor + rot skew + scale")
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--
|
||||
-- SpriteOffsetAnchorFlip
|
||||
--
|
||||
local SpriteOffsetAnchorFlip = {}
|
||||
function SpriteOffsetAnchorFlip.initLayer(layer)
|
||||
local s = CCDirector:sharedDirector():getWinSize()
|
||||
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:addSpriteFramesWithFile("animations/grossini.plist")
|
||||
cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png")
|
||||
|
||||
for i = 0, 2 do
|
||||
-- Animation using Sprite batch
|
||||
local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png")
|
||||
sprite:setPosition(ccp(s.width / 4 * (i + 1), s.height / 2))
|
||||
|
||||
local point = CCSprite:create("Images/r1.png")
|
||||
point:setScale(0.25)
|
||||
point:setPosition(sprite:getPosition())
|
||||
layer:addChild(point, 1)
|
||||
|
||||
if i == 0 then
|
||||
sprite:setAnchorPoint(ccp(0, 0))
|
||||
elseif i == 1 then
|
||||
sprite:setAnchorPoint(ccp(0.5, 0.5))
|
||||
else
|
||||
sprite:setAnchorPoint(ccp(1, 1))
|
||||
end
|
||||
|
||||
point:setPosition(sprite:getPosition())
|
||||
|
||||
local animFrames = CCArray:create()
|
||||
for j = 0, 13 do
|
||||
local frame = cache:spriteFrameByName(string.format("grossini_dance_%02d.png", j+1))
|
||||
animFrames:addObject(frame)
|
||||
end
|
||||
|
||||
local animation = CCAnimation:createWithSpriteFrames(animFrames, 0.3)
|
||||
sprite:runAction(CCRepeatForever:create(CCAnimate:create(animation)))
|
||||
|
||||
local flip = CCFlipY:create(true)
|
||||
local flip_back = CCFlipY:create(false)
|
||||
local delay = CCDelayTime:create(1)
|
||||
local delay2 = CCDelayTime:create(1)
|
||||
|
||||
local actionArray = CCArray:create()
|
||||
actionArray:addObject(delay)
|
||||
actionArray:addObject(flip)
|
||||
actionArray:addObject(delay2)
|
||||
actionArray:addObject(flip_back)
|
||||
local seq = CCSequence:create(actionArray)
|
||||
sprite:runAction(CCRepeatForever:create(seq))
|
||||
|
||||
layer:addChild(sprite, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorFlip.eventHandler(tag)
|
||||
if tag == "exit" then
|
||||
local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
|
||||
cache:removeSpriteFramesFromFile("animations/grossini.plist")
|
||||
cache:removeSpriteFramesFromFile("animations/grossini_gray.plist")
|
||||
end
|
||||
end
|
||||
|
||||
function SpriteOffsetAnchorFlip.create()
|
||||
local layer = CCLayer:create()
|
||||
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
|
||||
|
||||
|
||||
function SpriteTest()
|
||||
local scene = CCScene:create()
|
||||
|
||||
|
@ -1123,10 +1612,14 @@ function SpriteTest()
|
|||
SpriteOffsetAnchorSkew.create,
|
||||
SpriteOffsetAnchorRotationalSkew.create,
|
||||
SpriteBatchNodeOffsetAnchorSkew.create,
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkew.create
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkew.create,
|
||||
SpriteOffsetAnchorSkewScale.create,
|
||||
SpriteOffsetAnchorRotationalSkewScale.create,
|
||||
SpriteBatchNodeOffsetAnchorSkewScale.create,
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkewScale.create,
|
||||
SpriteOffsetAnchorFlip.create
|
||||
}
|
||||
|
||||
ActionIdx = 0
|
||||
scene:addChild(Sprite1.create())
|
||||
scene:addChild(CreateBackMenuItem())
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
f69ec53c941b1d3790a138b08d94b14e0db78442
|
||||
a4f7260b60cbb186bd99e15372b41c55ddfea89c
|
|
@ -94,9 +94,10 @@ class CCRotateTo : public CCActionInterval
|
|||
|
||||
class CCRotateBy : public CCActionInterval
|
||||
{
|
||||
CCActionInterval* reverse(void);
|
||||
CCActionInterval* reverse(void);
|
||||
|
||||
static CCRotateBy* create(float duration, float fDeltaAngle);
|
||||
static CCRotateBy* create(float duration, float fDeltaAngleX, float DeltaAngleY);
|
||||
};
|
||||
|
||||
class CCMoveTo : public CCActionInterval
|
||||
|
|
Loading…
Reference in New Issue