在 AndEngine 中使用复杂的数学路径移动精灵

发布于 2024-12-25 10:59:49 字数 132 浏览 1 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2025-01-01 10:59:49

计算您的位置并将其存储到两个 float 数组中。第一个数组中的每个单元格都是 X 坐标,第二个数组中的每个单元格都是 Y 坐标。

然后,创建一个 Path 对象。确保它是 AndEngine 的 Path 对象,而不是常规 Android SDK 对象(AndEngine 对象是 org.anddev.andengine.entity.modifier.PathModifier.Path)。
以这种方式创建您的 Path

Path path = new Path(coordinatesX, coordinatesY);

其中 coordinatesXcoordinatesY 当然是 float 数组。

现在,您所要做的就是使用 Path 创建一个 PathModifier:(

PathModifier modifier = new PathModifier(duration, path);
modifier.setRemoveWhenFinished(true);

duration 是一个 float,指定实体沿路径移动的时间越小,实体移动的速度就越快,尝试不同的时间以找出最适合您的时间。

使用 true 参数调用 setRemoveWhenFinished 可确保在路径完成时取消注册路径修饰符。

然后只需将其注册到您的精灵:

sprite.registerEntityModifier(modifier);

就完成了。

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's Path object, not the regular Android SDK one (AndEngine one is org.anddev.andengine.entity.modifier.PathModifier.Path).
Create your Path this way:

Path path = new Path(coordinatesX, coordinatesY);

Where coordinatesX and coordinatesY are, of course, float arrays.

Now, all you have to do is create a PathModifier with your Path:

PathModifier modifier = new PathModifier(duration, path);
modifier.setRemoveWhenFinished(true);

(duration is a float 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 a true argument makes sure the path modifier will be unregistered when the path is completed.

Then just register it to your sprite:

sprite.registerEntityModifier(modifier);

And you are done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文