在 AndEngine 中使用复杂的数学路径移动精灵
我是 AndEngine 编程的新手。我想在用户与其交互之前移动重新创建复杂动画的精灵。 精灵的初始运动并不是那么线性,也不是那么简单。我想对移动精灵的坐标应用复杂的数学算法。 我怎样才能做到这一点?我可以在 AndEngine 中使用哪些现有函数?
I'm new to AndEngine programming. I want to move a sprite recreating a complex animation before the user can interact with it.
The initial movement of the sprite is not so linear and not so simple. I want to apply a complex Mathematical algorithm to the coordinates of the moving sprite.
How can I achieve this ? Which existing functions can I use in AndEngine ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
计算您的位置并将其存储到两个
float
数组中。第一个数组中的每个单元格都是 X 坐标,第二个数组中的每个单元格都是 Y 坐标。然后,创建一个
Path
对象。确保它是 AndEngine 的 Path 对象,而不是常规 Android SDK 对象(AndEngine 对象是 org.anddev.andengine.entity.modifier.PathModifier.Path)。以这种方式创建您的
Path
:其中
coordinatesX
和coordinatesY
当然是float
数组。现在,您所要做的就是使用
Path
创建一个PathModifier
:(duration
是一个float
,指定实体沿路径移动的时间越小,实体移动的速度就越快,尝试不同的时间以找出最适合您的时间。使用
true
参数调用setRemoveWhenFinished
可确保在路径完成时取消注册路径修饰符。然后只需将其注册到您的精灵:
就完成了。
Calculate your positions and store them into two
float
arrays. Each cell in the first array would be a X coordinate, and in the second array it would be a Y coordinate.Then, create a
Path
object. Make sure it is AndEngine'sPath
object, not the regular Android SDK one (AndEngine one isorg.anddev.andengine.entity.modifier.PathModifier.Path
).Create your
Path
this way:Where
coordinatesX
andcoordinatesY
are, of course,float
arrays.Now, all you have to do is create a
PathModifier
with yourPath
:(
duration
is afloat
specifying the time for the entity will move along the path. The smaller it is, the faster the entity moves. Experiment with different times to find out what works the best for you).Calling
setRemoveWhenFinished
with atrue
argument makes sure the path modifier will be unregistered when the path is completed.Then just register it to your sprite:
And you are done.