根据鱼精灵帧资源或炸弹精灵帧资源中鱼或炸弹的头部朝向设置精灵的rotation,整体不动的圆轨迹暂不设置精灵的rotation,对于正弦轨迹这类非圆曲线轨迹设置rotation,修改FishManage:addOneGroupFish和Fish:addPath这两个函数,添加必要的接口说明
--鱼的头部朝向
s_AllFishArg={[1]=math.pi,[2]=math.pi,[3]=0,[4]=math.pi,[5]=math.pi,[6]=math.pi,[7]=math.pi,[8]=math.pi,[9]=math.pi,[10]=math.pi*0.5,[12]=math.pi,[15]=math.pi,[18]=math.pi,[20]=math.pi,[25]=math.pi,[30]=math.pi,[40]=math.pi}
--炸弹的头部朝向
s_AllBombArg={[1]=math.pi,[2]=math.pi,[3]=math.pi,[4]=math.pi,[5]=math.pi,[6]=math.pi,[7]=math.pi,[8]=math.pi,[9]=math.pi,[10]=math.pi,[11]=0,[12]=math.pi}
--取商、取模
function qr(fishType)
local q=math.floor(fishType/100)
local r=fishType-math.floor(fishType/100)*100
return q,r
end
--鱼的头部朝向
--[[
fishType=1,2,40,……,——pi
fishType=3,——0
fishType=10,——pi*0.5
]]
function qrArg(fishType)
local q,r=qr(fishType)
if q==0 then
local arg=s_AllFishArg[r]
return arg
else
local arg=s_AllBombArg[r]
return arg
end
end
--[[
具体的运动轨迹由轨迹类型、轨迹起点坐标、轨迹速度等相互独立的参数来控制
参数说明:
pathType--轨迹类型
1表示直线轨迹,额外参数arg1表示轨迹方向,例如pathType=1,arg1=ccp(1500,1500)表示右上角45度直线轨迹;pathType=1,arg1=ccp(1500,0)表示水平向右直线轨迹
2表示圆轨迹
3表示摆线轨迹,额外参数arg1代表半径和辐角主值增量,额外参数arg2代表摆线轨迹方向
arg1--第一个额外参数,直线轨迹、圆轨迹、摆线轨迹要用到
arg2--第二个额外参数,摆线轨迹要用到
]]
function Fish:addPath(pathType,arg1,arg2)
if(pathType==1)then
--给定轨迹起点和恒定速度矢量(恒定速率和恒定方向)的匀速直线运动
--对于直线轨迹,arg1代表直线轨迹方向,例如ccp(1500,1500)代表右上角45度直线轨迹,ccp(1500,0)代表水平向右直线轨迹
if(arg1==nil)then
arg1=CCPoint(1500,0);
end
--根据鱼帧资源中的鱼头部方向和鱼轨迹方向设置顺时针旋转角度(角度制)
local angle=(qrArg(self:getTag())-math.atan2(arg1.y,arg1.x))*180/math.pi
self:setRotation(angle);
local actionMove = CCMoveBy:create(15.0,arg1);
--在轨迹时长内,鱼精灵对象会删除自身
local pcc=CCCallFunc:create(function()
self:removeFromParentAndCleanup(true)
end)
local sq = CCSequence:createWithTwoActions(actionMove,pcc);
self:runAction(sq);
end
if(pathType==2)then
local startP=CCPoint(self:getPositionX(),self:getPositionY());
--对于圆轨迹,arg1代表圆心坐标
if(arg1==nil)then
arg1=CCPoint(self:getPositionX()-150,self:getPositionY());
end
self:runAction(myAction:createCircle(60.0,"CircleTraceFunc",startP,arg1,20));
--[[
local startP=CCPoint(self:getPositionX(),self:getPositionY());
--对于圆轨迹,arg1代表圆心坐标
if(arg1==nil)then
arg1=CCPoint(self:getPositionX()+150,self:getPositionY());
end
--对径点P
local P=CCPoint(arg1.x*2-self:getPositionX(),arg1.y*2-self:getPositionY());
local actionBy = CircleAction:create(5.0,P,1);
local ac = CCRepeatForever:create(actionBy);
self:runAction(ac);
--圆顺时针运动轨迹,参数一为动画时长,参数二为当前圆上位置的对径点坐标,参数三为轨迹方向
self:runAction(CircleAction:create(3.0, ccp(500,300),-1));
]]
end
if(pathType==3)then
--[[
--去掉了createMoveCircle,用createCycloid代替
local actionBy =myAction:createCycloid(3.0,"CycloidTraceFunc",ccp(200,300),ccp(50,0),3,ccp(-50,math.pi*0.25));
local ac = CCRepeatForever:create(actionBy);
self:runAction(ac);
]]
local startP=CCPoint(self:getPositionX(),self:getPositionY());
--对于摆线轨迹,arg1代表半径和辐角主值增量
if(arg1==nil)then
arg1=CCPoint(50,0);
end
--对于摆线轨迹,arg2.y代表摆线轨迹方向
if(arg2==nil)then
arg2=ccp(0,math.pi);
end
local angle=(qrArg(self:getTag())-arg2.y)*180/math.pi
self:setRotation(angle);
local actionMove = myAction:createCycloid(15.0,"CycloidTraceFunc",startP,arg1,3,arg2)
local pcc=CCCallFunc:create(function()
self:removeFromParentAndCleanup(true)
end)
local sq = CCSequence:createWithTwoActions(actionMove,pcc);
self:runAction(sq);
end
if(pathType==4)then
--自定义运动轨迹,参数一为动画时长,参数二为表示轨迹参数方程的LUA函数名
--self:runAction(myAction:create(3.0,"SinTrace"));
local angle=(qrArg(self:getTag())-0)*180/math.pi
--创建一个先加速再减速的正弦曲线轨迹运动
local pAction=myAction:create(3.0,"SinTrace");
local move_ease_inout = CCEaseInOut:create(pAction,2);
self:runAction(move_ease_inout);
end
if(pathType==5)then
self:moveWithParabola(ccp(200, 300), ccp(500, 300), 0.0, 20.0, 3.0);
end
end
--[[
添加一个鱼阵
参数说明:
fishgroupType----鱼阵类型:1*表示直线轨迹阵,2*表示圆轨迹阵,3*表示摆线轨迹阵
鱼阵类型fishgroupType和轨迹类型pathType最好对应起来,增强LUA代码的可读性
pathType----轨迹类型:1表示直线轨迹,2表示圆轨迹,3表示摆线轨迹
]]
function FishManage:addOneGroupFish(fishgroupType)
--水平直线轨迹阵
if(fishgroupType==11)then
FishManage:addOneFish(12,1,ccp(0,300),ccp(1500,0));
FishManage:addOneFish(12,1,ccp(0,350),ccp(1500,0));
FishManage:addOneFish(12,1,ccp(0,250),ccp(1500,0));
end
--斜直线轨迹阵
if(fishgroupType==12)then
FishManage:addOneFish(10,1,ccp(-50,50),ccp(1500,1500))
FishManage:addOneFish(10,1,ccp(-25,75),ccp(1500,1500))
FishManage:addOneFish(10,1,ccp(0,100),ccp(1500,1500))
FishManage:addOneFish(10,1,ccp(-70,25),ccp(1500,1500))
end
--圆轨迹阵
if(fishgroupType==21)then
local startP=ccp(500,300)
local centerP=ccp(350,300)
local deltArg=math.pi*0.2
for i=1,10 do
local startP=GetCirclePos(startP,centerP,deltArg*(i-1))
FishManage:addOneFish(1,2,startP,centerP)
end
end
--[[
--圆轨迹阵
if(fishgroupType==22)then
local startP=ccp(0,300)
local centerP=ccp(150,300)
local deltArg=math.pi*0.2
for i=1,10 do
local startP=GetCirclePos(startP,centerP,deltArg*(i-1))
FishManage:addOneFish(7,2,startP,centerP)
end
end
]]
----水平摆线轨迹阵
if(fishgroupType==31)then
local startP=ccp(200,300)
local rdeltArg=ccp(60,0)
local arg2=ccp(0,math.pi)
local deltArg=math.pi*0.2
for i=1,10 do
rdeltArg.y=deltArg*(i-1)
FishManage:addOneFish(1,3,startP,rdeltArg,arg2)
end
end
--斜摆线轨迹阵
if(fishgroupType==32)then
local startP=ccp(400,300)
local rdeltArg=ccp(100,0)
local arg2=ccp(0,math.pi*0.75)
local deltArg=math.pi*0.2
for i=1,10 do
rdeltArg.y=deltArg*(i-1)
FishManage:addOneFish(6,3,startP,rdeltArg,arg2)
end
end
--垂直摆线轨迹阵
if(fishgroupType==33)then
local startP=ccp(400,300)
local rdeltArg=ccp(60,0)
local arg2=ccp(0,math.pi*0.5)
local deltArg=math.pi*0.2
for i=1,10 do
rdeltArg.y=deltArg*(i-1)
FishManage:addOneFish(2,3,startP,rdeltArg,arg2)
end
end
end
function onCCControlEventTouchUpInside(pSender,name)
CCLuaLog("SceneGame.pSender["..tostring(pSender).."].name["..name.."].onCCControlEventTouchUpInside")
--add by Ivan_han
if name=="Help" then--【帮助】
FishManage:addOneFish(112,1,CCPoint(200,300),CCPoint(1500,0))
elseif name=="Set" then--【设置】
FishManage:addOneGroupFish(33)
elseif name=="Supplement" then--【充值中心】
--FishManage:addOneFish(1,2,ccp(500,300),ccp(350,300))
--FishManage:addOneGroupFish(21)
FishManage:addOneFish(2,2,ccp(500,300),ccp(350,300))
elseif name=="MyDepot" then--【我的仓库】
--FishManage:addOneFish(1,1,ccp(0,100))
FishManage:addOneGroupFish(12)
elseif name=="Gam" then--【社交】
--FishManage:addOneFish(1,3,CCPoint(200,300),CCPoint(50,0),CCPoint(0,0))
--FishManage:addOneGroupFish(31)
FishManage:addOneFish(107,2,ccp(0,300),ccp(150,300))
elseif name=="Shop" then--【商城】
FishManage:addOneFish(1,4)
--FishManage:addOneGroupFish(32)
elseif name=="Bullet" then--【子弹】
--FishManage:addOneFish(1,4)
FishManage:addOneFish(101,4)
elseif name=="Task" then--【任务】
FishManage:addOneGroupFish(11)
else
FishManage:CaptureOneFish()--【成就】、【结算退出】
end
end