您的位置:首页 > 移动开发 > Cocos引擎

cocos-抛物线运动

2016-06-20 10:23 489 查看
local star_pos = cc.p(40,40)

local end_pos = cc.p(50,50)

local width =  math.abs(end_pos.x -  start_pos.x)

local height =  math.abs(end_pos.y -  start_pos.y)

--准线焦点

local focal_x = star_pos.x + width / 2

local focal_y = star_pos.y -  height

local b = ((star_pos.y-end_pos.y) * (star_pos.x*star_pos.x-focal_x*focal_x)-(star_pos.y-y2) *(star_pos.x*star_pos.x-end_pos.x * end_pos.x)) / ((star_pos.x-end_pos.x) * (star_pos.x * star_pos.x-focal_x * focal_x)-(star_pos.x-focal_x) * (star_pos.x * star_pos.x-end_pos.x
* end_pos.x))

local a = ((star_pos.y-y2)-b * (star_pos.x-focal_x))/(star_pos.x*star_pos.x-focal_x * focal_x)

local c = star_pos.y-a * star_pos.x  * star_pos.x- b * star_pos.x
local vx = width / 5  --速度为 width / 5

local function run_PwAction(dt)

    local nowx,nowy = self:getPosition()

    local xp = nowx + dt * vx

    local yp = xp * a * xp + b * xp + c

    self:setPosition(xp,xp)

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: