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
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
相关文章推荐
- cocos-笔记-判断方向-屏幕
- COCOS官网文档
- [zz]cocos2d-x如何优化内存的应用
- [zz]cocos2d-x如何优化内存的应用
- [zz]cocos2d-x如何优化内存的应用
- [zz]cocos2d-x如何优化内存的应用
- quick-cocos2d-x踩坑记
- cocos 自定义事件
- cocos studio做的元件侦听
- cocos 代码添加背景
- cocos 动画整理
- cocos 进入后台的侦听器
- COCOS 屏蔽一个layer
- cocos js 遮罩示例代码
- Cocos2d-x之层间切换
- cocos2dx 历史版本下载问题
- Cococs2d-x之解决cocos2d项目编译速度慢的问题
- 开始cocos2dx学习小记:MacOS下使用cocos2dx创建项目遇到permission denied
- Cocos2d-x之helloworld
- Cocos2d-x之下载安装和配置