added an update method to handle calculation

This commit is contained in:
Sem van der Hoeven
2020-05-11 11:55:49 +02:00
parent f9c0a4834e
commit 0253cc1a28

View File

@@ -9,6 +9,8 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import netwerkprog.game.client.Client;
import netwerkprog.game.server.Server;
public class MainGame extends ApplicationAdapter { public class MainGame extends ApplicationAdapter {
SpriteBatch batch; SpriteBatch batch;
@@ -33,20 +35,34 @@ public class MainGame extends ApplicationAdapter {
music.setVolume(.1f); music.setVolume(.1f);
music.play(); music.play();
music.setLooping(true); music.setLooping(true);
connectToServer();
}
private void connectToServer() {
Client client = new Client("localhost", Server.PORT);
client.start();
} }
@Override @Override
public void render() { public void render() {
update();
Gdx.gl.glClearColor(xPos/Gdx.graphics.getWidth(), 0, 0, 1); Gdx.gl.glClearColor(xPos/Gdx.graphics.getWidth(), 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin(); batch.begin();
updatePos();
batch.draw(img, xPos, yPos); batch.draw(img, xPos, yPos);
batch.end(); batch.end();
frameRate.update();
frameRate.render(); frameRate.render();
} }
/**
* update method that does all calculation before something is being drawn
*/
public void update() {
frameRate.update();
updatePos();
}
private void updatePos() { private void updatePos() {
yPos += yUpdate; yPos += yUpdate;
xPos += xUpdate; xPos += xUpdate;