感谢2位大佬的贡献
--[[
椭圆运动轨迹 by 胡广超
]]
local LRActionInterval = class("LRActionInterval")
local sin = math.sin
local cos = math.cos
function LRActionInterval:tuoyuanXat(angle)--返回X坐标
return self._aLength*cos(angle) --参数方程
end
function LRActionInterval:tuoyuanYat(angle)--返回Y坐标
return self._bLength*sin(angle)
end
function LRActionInterval:create(args)
local obj = LRActionInterval.new(args)
if obj then
obj:init(args)
end
return obj
end
function LRActionInterval:init(args)
local detlaAngle = args.detlaAngleor or 10-- 变化角度
local startAngle = args.startAngle or 0-- 初始角度
self._detlaAngle = 2* math.pi * detlaAngle/360
self._startAngle = 2* math.pi * startAngle/360
self._center = args.center or cc.p(500,200)
self._time = 0
self._aLength = args.a or 200
self._bLength = args.b or 120
self._pTarget = args.node
self._parent = args.parent --父节点
self.speed = args.speed --旋转速度
self:setTarget(self._pTarget, self._parent)
end
function LRActionInterval:setTarget(node,parent)
if parent then
self.drawNode = cc.DrawNode:create()
parent:addChild(self.drawNode)
end
local x = self:tuoyuanXat(self._startAngle)
local y = self:tuoyuanYat(self._startAngle)
local pos = cc.p(x + self._center.x, y + self._center.y)
self._pTarget:setPosition(pos)
end
function LRActionInterval:star()
self.scheduleTimeID = g_scheduleScriptFunc(handler(self,self.update), 0.01)
end
function LRActionInterval:close()
if self.scheduleTimeID then
g_unscheduleScriptEntry(self.scheduleTimeID )
self.scheduleTimeID = nil
end
end
function LRActionInterval:update(time_)
self._time = self._time - time_
if self._pTarget then
local angle = self._startAngle + self._detlaAngle * self._time*self.speed
local x = self:tuoyuanXat(angle)
local y = self:tuoyuanYat(angle)
local pos = cc.p(x + self._center.x, y + self._center.y)
self._pTarget:setPosition(pos)
if self.drawNode then
self.drawNode:drawPoint(pos, 2, cc.c4f(1, 0, 0, 1))
end
end
end
return LRActionInterval
使用样例 by 刘新夏
self.tbSch = {}
local detla = {0,90,180,270}
for i=1,4 do
local title = g_seekWidgetByName(self._root, "btn_tpye_"..i, handler(self, self.btnChooseTypeFun))
title:setTag(i)
g_seekWidgetByName(title,"Image_11"):hide()
g_seekWidgetByName(title,"Image_12"):hide()
local pos = cc.p(title:getPosition())
table.insert(_title,i,title)
table.insert(title_pos,i,pos)
table.insert(cur_pos,i)
local size = title:getParent():getContentSize()
local args = { startAngle = detla[i], node = title ,center = cc.p(size.width/2,size.height/2), a = 200, b = 120, speed = 1}
local lra = LRActionInterval:create(args)
lra:star()
table.insert(self.tbSch, lra)
end