Physics body attached to the player entity now

This commit is contained in:
Allexit 2015-04-09 21:32:36 +03:00
parent 822d2fa7bc
commit 1727c43265
3 changed files with 6 additions and 5 deletions

View File

@ -98,8 +98,6 @@ public class GladiatorBrawler extends ApplicationAdapter {
box.dispose();
player = new Entity();
CRenderedObject renderedObject = new CRenderedObject();
@ -110,7 +108,7 @@ public class GladiatorBrawler extends ApplicationAdapter {
renderedObject.setCurrentSequence("Idle");
player.add(renderedObject);
player.add(new CPhysics());
player.getComponent(CPhysics.class).position.set(body.getPosition());
player.getComponent(CPhysics.class).body = body;
engine.addEntity(player);
}

View File

@ -2,10 +2,11 @@ package com.saltosion.gladiator.components;
import com.badlogic.ashley.core.Component;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
public class CPhysics extends Component {
public Vector2 position = new Vector2(0, 0);
public Body body;
public Vector2 velocity = new Vector2(0, 0);
}

View File

@ -69,7 +69,9 @@ public class RenderingSystem extends EntitySystem {
int spriteHeight = currSprite.getRegionHeight();
int spriteWidth = currSprite.getRegionWidth();
currSprite.setPosition(physics.position.x-spriteWidth/2, physics.position.y-spriteHeight/2);
currSprite.setPosition(physics.body.getPosition().x-spriteWidth/2,
physics.body.getPosition().y-spriteHeight/2);
currSprite.setRotation(physics.body.getAngle());
currSprite.draw(batch);
float nextFrame = renderedObject.getCurrentFrame() + deltaTime*currSequence.getPlayspeed();