issue #1803:add SpriteBatchNodeOffsetAnchorSkewScale

This commit is contained in:
minggo 2013-03-14 15:49:20 +08:00
parent 815733e0b7
commit e47baa7984
1 changed files with 91 additions and 1 deletions

View File

@ -1341,6 +1341,95 @@ function SpriteOffsetAnchorRotationalSkewScale.create()
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
function SpriteTest()
local scene = CCScene:create()
@ -1361,7 +1450,8 @@ function SpriteTest()
SpriteBatchNodeOffsetAnchorSkew.create,
SpriteBatchNodeOffsetAnchorRotationalSkew.create,
SpriteOffsetAnchorSkewScale.create,
SpriteOffsetAnchorRotationalSkewScale.create
SpriteOffsetAnchorRotationalSkewScale.create,
SpriteBatchNodeOffsetAnchorSkewScale.create
}
scene:addChild(Sprite1.create())