出于某种原因,当我在没有libgdx的先前物理测试中使用相同的代码时,它工作正常。但是对于libgdx,它认为地面在天空中。
package com.me.randomtests;
import com.badlogic.gdx.ApplicationListener;
import...
public class Randomtest implements ApplicationListener {
ShapeRenderer SR;
int x = 100, y = 100, radius = 10;
double deltax = 0, deltay = 0, gravity = 15, energyloss = .65, dt = .2;
@Override
public void create() {
SR=new ShapeRenderer();
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
SR.begin(ShapeType.FilledCircle);
SR.filledCircle(x, y, radius);
SR.setColor(Color.BLUE);
SR.end();
Update();
}
public void Update(){
System.out.println(y);
if(x + deltax > Gdx.graphics.getWidth() - radius -1 ){
x = Gdx.graphics.getWidth() - radius - 1;
deltax = - deltax;
}else if(x + deltax < 0 + radius){
x = 0+radius;
deltax= - deltax;
}else{
x += deltax;
}
if(y>Gdx.graphics.getHeight() - radius - 1){
y = Gdx.graphics.getHeight() - radius - 1;
deltay *=.9;
deltay = -deltay;
}else{
//vel formuka
deltay += gravity *dt;
//pos formula
y +=deltay*dt + .5*gravity*dt*dt;
}
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
我的问题在这里?也有人知道为什么0在libgdx底部?