欢迎各位童鞋转载,转载请注明出处:http://blog.youkuaiyun.com/song_hui_xiang
作者新浪微博:http://weibo.com/u/3168848533
作者腾讯微博:http://t.qq.com/song_huixiang
local size = CCDirector:sharedDirector():getWinSize()
local layer = CCLayer:create()
local man = CCSprite:create("man.png")
local blackgirl = CCSprite:create("blackgirl.png")
local whitegirl = CCSprite:create("whitegirl.png")
blackgirl:setPosition(ccp(size.width*0.5,size.height*0.66))
whitegirl:setPosition(ccp(size.width*0.5,size.height*0.5))
man:setPosition(ccp(size.width*0.5,size.height*0.33))
layer:addChild(man,1)
layer:addChild(blackgirl,2)
layer:addChild(whitegirl)
local function ActionManual()
man:setScaleX(2.5)
--负值得到镜像
man:setScaleY(-1)
--man:setScale(-1)
man:setOpacity(128)
blackgirl:setRotation(120)
--blackgirl:setRotation(-120)
blackgirl:setColor(ccc3(255,0,0))
whitegirl:setColor(ccc3(0,0,255))
end
--ActionManual()
--移动动画
local function ActionMove()
local actionBy = CCMoveBy:create(2,ccp(100,100))
local actionByBack = actionBy:reverse()
man:runAction(CCMoveTo:create(1,ccp(size.width*0.5-100,size.height*0.33-100)))
whitegirl:runAction(CCSequence:createWithTwoActions(actionBy,actionByBack))
blackgirl:runAction(CCMoveTo:create(1,ccp(40,40)))
--对于CC...To的动作,reverse()是不支持的
--blackgirl:runAction(CCSequence:createWithTwoActions(actionTo,actionTo:reverse()))
end
--ActionMove()
--缩放动画
local function ActionScale()
--[[
local scaleTo = CCScaleTo:create(2,5)
local scaleTo2 = CCScaleTo:create(2,1)
whitegirl:runAction(CCSequence:createWithTwoActions(scaleTo,scaleTo2))
local scaleBy = CCScaleBy:create(2,2.5)
--local scaleBy2 = CCScaleBy:create(2,1)
local scaleBy2 = scaleBy:reverse()
blackgirl:runAction(CCSequence:createWithTwoActions(scaleBy,scaleBy2))
--]]
local scaleTo = CCScaleTo:create(2,0.5)
local scaleBy = CCScaleBy:create(2,1,10)
local scaleBy2 = CCScaleBy:create(2,5)
--对于CC...To的动作,reverse()是不支持的
--local scaleTo2 = scaleTo:reverse()
--man:runAction(CCSequence:createWithTwoActions(scaleTo,scaleTo2))
man:runAction(scaleTo)
whitegirl:runAction(CCSequence:createWithTwoActions(scaleBy,scaleBy:reverse()))
blackgirl:runAction(CCSequence:createWithTwoActions(scaleBy2,scaleBy2:reverse()))
end
--ActionScale()
--旋转动画
local function ActionRotate()
local rotateTo = CCRotateTo:create(2,45)
local rotateTo2 = CCRotateTo:create(2,0)
man:runAction(CCSequence:createWithTwoActions(rotateTo,rotateTo2))
--如果CC...To的什么动作执行了reverse(),则控制台报错如下:Cocos2d: [LUA ERROR] ASSERT FAILED ON LUA EXECUTE: CCIntervalAction: reverse not implemented.
--man:runAction(CCSequence:createWithTwoActions(rotateTo,rotateTo:reverse()))
local rotateBy = CCRotateBy:create(2,360)
whitegirl:runAction(CCSequence:createWithTwoActions(rotateBy,rotateBy:reverse()))
local rotateTo3 = CCRotateTo:create(2,-45)
local rotateTo4 = CCRotateTo:create(2,0)
blackgirl:runAction(CCSequence:createWithTwoActions(rotateTo3,rotateTo4))
end
--ActionRotate()
--扭曲动作:这个动画是我在本节中遇到的最难解释的动画。我想了好久该怎么说,却仍然有些晦涩。扭曲动画可以理解为对精灵的两对对角分别进行X,Y方向的拉伸扭曲到目标角度的动画。
local function ActionSkew()
local skewTo = CCSkewTo:create(2,40,40)
local skewTo2 = CCSkewTo:create(2,0,0)
man:runAction(CCSequence:createWithTwoActions(skewTo,skewTo2))
--man:removeFromParentAndCleanup(true)
local skewBy = CCSkewBy:create(2,50,-50)
local skewBy2 = skewBy:reverse()
blackgirl:runAction(CCSequence:createWithTwoActions(skewBy,skewBy2))
local shewBy3 = CCSkewBy:create(2,0,90)
whitegirl:runAction(CCSequence:createWithTwoActions(shewBy3,shewBy3:reverse()))
end
ActionSkew()
local scene = CCScene:create()
scene:addChild(layer)
CCDirector:sharedDirector():runWithScene(scene)