Implemented render Prediction

This commit is contained in:
Gulum
2017-10-19 01:28:40 +02:00
parent 18c3ce89b5
commit f650bea7ad
2 changed files with 11 additions and 6 deletions

View File

@@ -67,7 +67,7 @@ public class DarkRP2D extends Game {
@Override
// GameLoop
public void render () {
accumulator += Gdx.graphics.getDeltaTime(); //Seconds to milliseconds
accumulator += Gdx.graphics.getRawDeltaTime(); //Seconds to milliseconds
//Process Input
Command currentCommand = CommandStream.pollCommand();
@@ -84,7 +84,7 @@ public class DarkRP2D extends Game {
skippedFrames++;
}
trueRender();
trueRender(accumulator / MS_PER_UPDATE);
}
public void update(float deltaTime) {
@@ -92,7 +92,7 @@ public class DarkRP2D extends Game {
engine.update(deltaTime);
}
public void trueRender() {
public void trueRender(float delta) {
Gdx.gl.glClearColor(0.f, 0.f, 0.f, 1.f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
@@ -108,7 +108,7 @@ public class DarkRP2D extends Game {
b2dbr.render(world, debugMatrix);
//TODO: will be later moved to Gamescreen
engine.getSystem(RenderSystem.class).render(batch);
engine.getSystem(RenderSystem.class).render(delta, batch);
//some testdrawing
batch.begin();

View File

@@ -11,6 +11,7 @@ import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.darkrp2d.entities.components.Mappers;
import com.darkrp2d.entities.components.PhysicComponent;
@@ -33,14 +34,18 @@ public class RenderSystem extends EntitySystem {
entities = engine.getEntitiesFor(Family.all(TextureComponent.class, PhysicComponent.class).get());
}
public void render(SpriteBatch batch) {
public void render(float delta, SpriteBatch batch) {
batch.begin();
for (int i = 0; i < entities.size(); ++i) {
Entity entity = entities.get(i);
PhysicComponent physics = Mappers.physicComponentMapper.get(entity);
TextureComponent texture = Mappers.textureComponentMapper.get(entity);
batch.draw(texture.tex, Box2DUtils.worldToScreen(physics.body.getPosition().x) - texture.tex.getWidth() / 2, Box2DUtils.worldToScreen(physics.body.getPosition().y) - texture.tex.getHeight()/2);
Vector2 vel = physics.body.getLinearVelocity();
vel.scl(1.f/60.f);
vel.scl(delta);
batch.draw(texture.tex, Box2DUtils.worldToScreen(physics.body.getPosition().x + vel.x) - texture.tex.getWidth() / 2, Box2DUtils.worldToScreen(physics.body.getPosition().y + vel.y) - texture.tex.getHeight()/2);
}
batch.end();
}