android游戏中的跳跃方法
我是Android游戏开发的新手,我开始了一个简单的游戏,机器人可以跳过进入的盒子。 我想在带有onTouchEvent的surface视图中调用我的droid.jump()方法(只需在屏幕上轻触一下) 我创建了一个名为Droid的类:android游戏中的跳跃方法,android,game-physics,Android,Game Physics,我是Android游戏开发的新手,我开始了一个简单的游戏,机器人可以跳过进入的盒子。 我想在带有onTouchEvent的surface视图中调用我的droid.jump()方法(只需在屏幕上轻触一下) 我创建了一个名为Droid的类: public class Droid { // Log Tag for Debugging public static final String LOG_TAG = "_1Projekt"; private Bitmap bitmap; // the ac
public class Droid {
// Log Tag for Debugging
public static final String LOG_TAG = "_1Projekt";
private Bitmap bitmap; // the actual bitmap
private int x; // the X coordinate
private int y; // the Y coordinate
private boolean touched; // if droid is touched/picked up
private Speed speed; // the speed with its directions
private long mLastTime;
public Droid(Bitmap bitmap, int x, int y) {
this.bitmap = bitmap;
this.x = x;
this.y = y;
this.speed = new Speed();
}
。。。。。。。
而jump()方法是我的问题。我想有一个平稳的跳跃,但我不知道如何计算与当前系统时间。
我的想法是机器人应该每一个时间段更新它的Y位置,并且应该以一个快速的速度开始,然后将其降低到0以获得一个平滑的跳跃。
但我不知道如何在while循环中计算这个。
我当前的跳转()
到目前为止,我只实现了跳跃的“向上”部分。
谢谢你的回答!问候DroidDude你可能想看看(第三篇帖子):
在主循环之前,请执行以下操作:
//Get the current time
timeStep = System.currentTimeMillis();
然后做你的事。然后在循环返回开始之前,请
// Hold to lock at FPS
while(System.currentTimeMillis()-timeStep < 1000/60);
//在FPS时保持锁定
而(System.currentTimeMillis()-timeStep<1000/60);
其中60是每秒要运行的帧数
此方法还允许您在计算后获得时间差
while循环,以了解渲染一个对象所需的时间
框架使用这个,你可以有一个变量,你可以乘以所有
您的增量为,以获得与帧无关的速度
例如,如果您除以运行所需的毫秒数
按16.666处理帧,当程序运行时,数字将等于1
以每秒60帧的速度运行。当帧速率较低时,需要更多的时间
毫秒来渲染帧,并且该因子变得更大
不过,一定要在重新喷漆之前把它放好。这就是电子游戏的方式
也在计时。我的视频游戏基本小程序代码中显示了一个示例
JAVA下的代码片段
当你的机器人到达最高高度时,可能会设置一个标志,然后重新使用你的回路,但是降低高度。这并不像我想象的那样。我想知道如何得到实际的帧速率。我需要的是降低跳跃时的加速度。
// Hold to lock at FPS
while(System.currentTimeMillis()-timeStep < 1000/60);