mirror of https://github.com/axmolengine/axmol.git
issue #1803:add SpriteOffsetAnchorRotationalSkewScale
This commit is contained in:
parent
0fe38f073c
commit
815733e0b7
|
@ -1255,6 +1255,93 @@ function SpriteOffsetAnchorSkewScale.create()
|
|||
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
|
||||
|
||||
|
||||
function SpriteTest()
|
||||
local scene = CCScene:create()
|
||||
|
||||
|
@ -1273,7 +1360,8 @@ function SpriteTest()
|
|||
SpriteOffsetAnchorRotationalSkew.create,
|
||||
SpriteBatchNodeOffsetAnchorSkew.create,
|
||||
SpriteBatchNodeOffsetAnchorRotationalSkew.create,
|
||||
SpriteOffsetAnchorSkewScale.create
|
||||
SpriteOffsetAnchorSkewScale.create,
|
||||
SpriteOffsetAnchorRotationalSkewScale.create
|
||||
}
|
||||
|
||||
scene:addChild(Sprite1.create())
|
||||
|
|
|
@ -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