Home > Database > Mysql Tutorial > body text

cocos2dx射箭等抛射物的简单解决方案

WBOY
Release: 2016-06-07 15:15:02
Original
1798 people have browsed it

也是从网上看来的,这里记录一下 原理是利用贝塞尔曲线弓箭的旋转来造成弓箭的抛物线效果。 贝赛尔曲线: ccBezierConfig bezier;bezier.controlPoint_1 = start;bezier.controlPoint_2 = ccp(start.x+(end.x-start.x)*0.5,start.y+(end.y-start.y)*0.5+100)

也是从网上看来的,这里记录一下

原理是利用贝塞尔曲线+弓箭的旋转来造成弓箭的抛物线效果。

贝赛尔曲线:

	ccBezierConfig bezier;
	bezier.controlPoint_1 = start;
	bezier.controlPoint_2 = ccp(start.x+(end.x-start.x)*0.5,start.y+(end.y-start.y)*0.5+100);
	bezier.endPosition = ccp(end.x, end.y);
	float duration = 1.0f;
	CCBezierTo *actionBezier = CCBezierTo::create(duration,bezier);
Copy after login

其中controlPoint_1是起始点,endPosition是贝塞尔曲线动画的结束点,最重要的controlPoint_2是曲线的走向,决定了曲线的最高点。想深入学习贝塞尔曲线的同学请看这里:http://www.jasondavies.com/animated-bezier/

然后是旋转动画:

	float angle = <span style="font-family: Arial, Helvetica, sans-serif;">45.0f</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span>
	CCRotateTo *actionRotate =CCRotateTo::create(duration,angle);
Copy after login


最后让两个动画同时播放:
	CCSpawn* actionSpawn = CCSpawn::createWithTwoActions(actionBezier,actionRotate);

Copy after login

好了,大功告成。

但是这样做了之后,感觉射箭效果仍然不理想,毕竟是投机取巧的方法。为了优化视觉效果,可以调整动画播放的速度。




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template