在LUA中测试变速动画:增加鱼的加速直线运动、减速直线运动、先加速再减速的正弦曲线轨迹运动
if(pathType==2)then
self:setPosition(CCPoint(200,300));
local pAction=CCMoveTo:create(3.0, ccp(500,300));--直线轨迹。参数一为动画时长,参数二为要移动到的目标点。
--创建一个加速直线运动(a>0)。1<r<2时,△a<0;r=2时,△a=0,a=2;r>2时,△a>0。
--local move_ease_in = CCEaseIn:create(pAction,2);--参数二r=2,加速度为a=2的匀加速直线运动
--local move_ease_in = CCEaseIn:create(pAction,5);--参数二r>2,加速度越来越大的变加速直线运动
--local move_ease_in = CCEaseIn:create(pAction,1.5);--参数二1<r<2,加速度越来越小的变加速直线运动
--self:runAction(move_ease_in);
--创建一个加速度越来越大的减速直线运动(a<0),r>1,△a>0
local move_ease_out = CCEaseOut:create(pAction,2);
self:runAction(move_ease_out);
end
if(pathType==8)then
--自定义运动轨迹,参数一为动画时长,参数二为表示轨迹参数方程的LUA函数名
--self:runAction(myAction:create(3.0,"SinTrace"));
--创建一个先加速再减速的正弦曲线轨迹运动
local pAction=myAction:create(3.0,"SinTrace");
local move_ease_inout = CCEaseInOut:create(pAction,2);
self:runAction(move_ease_inout);
end
CCSpawn不能实现位移动作的合成
向上位移:
if(pathType==1)then
--self:moveWithParabola(ccp(200, 300), ccp(500, 300), 0.0, 20.0, 3.0);
self:setPosition(CCPoint(200,300));
local actionTo = CCMoveTo:create(3, ccp(500,300));
local actionToUp = CCMoveTo:create(3, ccp(200,500));
--local ac = CCSpawn:createWithTwoActions(actionTo,CCFadeOut:create(2));
local ac = CCSpawn:createWithTwoActions(actionTo,actionToUp);
self:runAction(ac);
end
向上位移:
if(pathType==1)then
--self:moveWithParabola(ccp(200, 300), ccp(500, 300), 0.0, 20.0, 3.0);
self:setPosition(CCPoint(200,300));
local actionBy = CCMoveBy:create(3, ccp(300,0));
local actionByUp = CCMoveBy:create(3, ccp(0,200));
--local ac = CCSpawn:createWithTwoActions(actionTo,CCFadeOut:create(2));
local ac = CCSpawn:createWithTwoActions(actionBy,actionByUp);
self:runAction(ac);
end
在LUA中测试无限次重复动画:增加鱼的给定轨迹起点和恒定速度矢量(恒定速率和恒定方向)的匀速直线运动、给定轨迹起点和恒定速率的匀速圆周运动
CCRepeatForever永远执行一个动作
if(pathType==1)then
--给定轨迹起点和恒定速度矢量(恒定速率和恒定方向)的匀速直线运动
self:setPosition(CCPoint(200,300));
local actionBy = CCMoveBy:create(1, ccp(300,0));
local ac = CCRepeatForever:create(actionBy);
self:runAction(ac);
end
if(pathType==3)then
--轨迹起点
self:setPosition(CCPoint(200,300));
--圆逆时针运动轨迹,参数一为动画时长,参数二为当前圆上位置的对径点坐标,参数三为轨迹方向
--给定轨迹起点和恒定速率的匀速圆周运动
self:setPosition(CCPoint(200,300));
local actionBy = CircleAction:create(1.0, ccp(500,300),1);
local ac = CCRepeatForever:create(actionBy);
self:runAction(ac);
end
在LUA中测试鱼轨迹:
1.根据鱼帧资源中的鱼头部方向和鱼轨迹方向设置顺时针旋转角度(角度制)
2.在轨迹时长内,鱼精灵对象会删除自身
if(pathType==1)then
--给定轨迹起点和恒定速度矢量(恒定速率和恒定方向)的匀速直线运动
--self:setPosition(CCPoint(200,300));
--[[
local actionBy = CCMoveBy:create(1, ccp(300,300));
local ac = CCRepeatForever:create(actionBy);
self:runAction(ac);
]]
--右上角45度直线轨迹
--local pAction=CCMoveBy:create(15.0, ccp(1500,1500));
--self:runAction(pAction);
--[[
local rnd = SIX_Utility:new():RNDNUM(1,2)
self:setRotation(180*0.5*rnd);--设置顺时针旋转角度(角度制)
]]
--根据鱼帧资源中的鱼头部方向和鱼轨迹方向设置顺时针旋转角度(角度制)
local angle=(math.pi-math.pi*0.25)*180/math.pi
self:setRotation(angle);
local actionMove = CCMoveBy:create(15.0, ccp(1500,1500));
--在轨迹时长内,鱼精灵对象会删除自身
local pcc=CCCallFunc:create(function()
self:removeFromParentAndCleanup(true)
end)
local sq = CCSequence:createWithTwoActions(actionMove,pcc);
self:runAction(sq);
end