我正在寻找一个教程,允许我制作一个简单的行跟踪应用程序,没有其他花哨的东西,如碰撞。如果我能得到一个对象来跟随这周末在屏幕上画的一条线,那就太棒了。
在熟悉了android之后,创建了一些应用程序(计算器、转换器),我想我已经准备好用一个包含主循环的游戏来加速它了。
我想这正是我要找的:http://www.rengelbert.com/tutorial.php?id=182
下面是演示:http://www.rengelbert.com/swf/LineDrawing.html
发布于 2012-02-25 08:23:36
您的问题实际上是相当模糊的,如果您确实提供了一些代码片段、变量、公式来帮助我们理解您的场景,则会有所帮助。我要做以下假设,以帮助我找到答案:
好了,现在我们已经建立了参数,我们可以提供一些Java代码:
// Define the line segment.
double x1 = /* ... insert value here */;
double y1 = /* ... insert value here */;;
double x2 = /* ... insert value here */;;
double y2 = /* ... insert value here */;;
// Determine both the direction and the length of the line segment.
double dx = x2 - x1;
double dy = y2 - y1;
double length = Math.sqrt(dx * dx + dy * dy); // length of the line segment
double orientation = Math.atan2(dy, dx);
// Now for any time 't' between 0 and length, let's calculate the object position.
double x = x1 + t * dx / length;
double y = y1 + t * dy / length;
showObjectAt(x, y, orientation);关于如何为您的应用程序构建游戏循环的教程,我强烈建议您遵循http://www.mybringback.com/上的系列,特别是Travis的Android教程,介绍如何在http://www.mybringback.com/tutorial-series/3266/android-the-basics-28-introduction-to-the-surfaceview/上使用SurfaceView对象
https://stackoverflow.com/questions/9441968
复制相似问题