mirror of https://github.com/axmolengine/axmol.git
issue #1803:add SpriteBatchNodeOffsetAnchorRotationalSkewScale
This commit is contained in:
parent
e47baa7984
commit
5936f4db2c
|
@ -1430,6 +1430,93 @@ function SpriteBatchNodeOffsetAnchorSkewScale.create()
|
|||
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
|
||||
|
||||
|
||||
function SpriteTest()
|
||||
local scene = CCScene:create()
|
||||
|
@ -1451,7 +1538,8 @@ function SpriteTest()
|
|||
SpriteBatchNodeOffsetAnchorRotationalSkew.create,
|
||||
SpriteOffsetAnchorSkewScale.create,
|
||||
SpriteOffsetAnchorRotationalSkewScale.create,
|
||||
SpriteBatchNodeOffsetAnchorSkewScale.create
|
||||
SpriteBatchNodeOffsetAnchorSkewScale.create,
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkewScale.create
|
||||
}
|
||||
|
||||
scene:addChild(Sprite1.create())
|
||||
|
|
Loading…
Reference in New Issue