Override setX and setY in Brick to update box2d body's position.

Clean up Ball and Paddle's overrides
This commit is contained in:
Matt Low 2018-11-20 21:01:41 +04:00
parent f90f5d5452
commit 2a398725f5
3 changed files with 18 additions and 14 deletions

View File

@ -154,17 +154,13 @@ public class Ball extends Entity implements PhysicsBody, CollisionListener {
@Override @Override
public void setX(float x) { public void setX(float x) {
super.setX(x); super.setX(x);
Vector2 bodyPos = body.getPosition(); body.setTransform(pos, 0);
bodyPos.x = x;
body.setTransform(bodyPos, 0);
} }
@Override @Override
public void setY(float y) { public void setY(float y) {
super.setY(y); super.setY(y);
Vector2 bodyPos = body.getPosition(); body.setTransform(pos, 0);
bodyPos.y = y;
body.setTransform(bodyPos, 0);
} }
public void setSpeed(float speed) { public void setSpeed(float speed) {

View File

@ -45,8 +45,8 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
this.shape = shape; this.shape = shape;
this.powerUpType = powerUpType; this.powerUpType = powerUpType;
this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888); this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888);
pm.setColor(type.getColor()); this.pm.setColor(type.getColor());
pm.fill(); this.pm.fill();
this.solid = new Texture(pm); this.solid = new Texture(pm);
this.region = new TextureRegion(solid); this.region = new TextureRegion(solid);
createBody(); createBody();
@ -196,6 +196,18 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
public void endContact(Entity contacted) { public void endContact(Entity contacted) {
} }
@Override
public void setX(float x) {
super.setX(x);
body.setTransform(pos, 0);
}
@Override
public void setY(float y) {
super.setY(y);
body.setTransform(pos, 0);
}
@Override @Override
public void dispose() { public void dispose() {
solid.dispose(); solid.dispose();

View File

@ -107,17 +107,13 @@ public class Paddle extends Entity implements PhysicsBody {
@Override @Override
public void setX(float x) { public void setX(float x) {
super.setX(x); super.setX(x);
Vector2 bodyPos = body.getPosition(); body.setTransform(pos, 0);
bodyPos.x = x;
body.setTransform(bodyPos, 0);
} }
@Override @Override
public void setY(float y) { public void setY(float y) {
super.setY(y); super.setY(y);
Vector2 bodyPos = body.getPosition(); body.setTransform(pos, 0);
bodyPos.y = y;
body.setTransform(bodyPos, 0);
} }
public float getWidth() { public float getWidth() {