如何在等距环境中移动计算抛出物体的路径?

发布于 2024-08-03 20:42:55 字数 129 浏览 4 评论 0原文

我正在 iPhone 上制作一个等距游戏,需要一些帮助。如果将对象从一个图块扔到另一个图块,那么计算该对象必须采取的路径的最佳方法是什么?我一直在研究使用 NSBezierPaths,但无法完全弄清楚如何将它们用于对象路径?任何帮助将不胜感激!

I am making an isometric game on the iPhone, and need a little help. What is the best way to go about calculating the path a object must take if it is thrown from one tile to another? I've been looking into using NSBezierPaths, but can't quite work out how to use them for the objects path? Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

鸢与 2024-08-10 20:42:55

我建议不要使用矢量图形(NSBezierPath)来完成您需要完成的任务。

您可以使用 CGPoint 来表示每个游戏对象的位置(假设这是一个 2D 游戏)。
(将此结构放入 GameObject 类中)。

struct objectPhysics
{
   CGPoint position;
   CGPoint velocity;
}

使用速度和方向向量来计算物体的轨迹。假设以下是向量:

position = position * velocity * timeDifference;

当事件发生时(例如用户点击某个对象或检测到碰撞),将速度向量设置为值 (1, 0.5) 或意味着在 X 方向移动 +1 和 0.5每帧的 Y 方向(如果有“* timeDifference”,则为时间单位)。

您应该访问此网站,了解有关开始游戏编程的提示以及一些矢量数学,您需要计算您需要加速的方向。

时间差是一种衡量标准自最后一帧以来已经过去了多少时间,用于确保对象移动正确的距离以与帧速率保持同步。

I would advise not using vector graphics (NSBezierPath) for what you need to accomplish.

You could use a CGPoint to represent the position for each game object (assuming this is a 2D game).
(Put this struct inside a GameObject class).

struct objectPhysics
{
   CGPoint position;
   CGPoint velocity;
}

Use speed and direction vectors to calculate the trajectory of the object. Assuming the following are vectors:

position = position * velocity * timeDifference;

When an event happens (such as the user clicking on an object or detecting a collision), set the velocity vector to a value (1, 0.5) or something which means move +1 in the X direction and 0.5 in the Y direction per frame (or unit of time if you have "* timeDifference").

You should take a look at this site for tips on beginning game programming and some of the vector math you will need in order to calculate the direction that you need to accelerate in.

The time difference is a measure of how much time has passed since the last frame is used to make sure that objects move the right distance to keep in sync with your frame rate.

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