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
public void setX(float x) {
super.setX(x);
Vector2 bodyPos = body.getPosition();
bodyPos.x = x;
body.setTransform(bodyPos, 0);
body.setTransform(pos, 0);
}
@Override
public void setY(float y) {
super.setY(y);
Vector2 bodyPos = body.getPosition();
bodyPos.y = y;
body.setTransform(bodyPos, 0);
body.setTransform(pos, 0);
}
public void setSpeed(float speed) {

View File

@ -45,8 +45,8 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
this.shape = shape;
this.powerUpType = powerUpType;
this.pm = new Pixmap(1,1, Pixmap.Format.RGBA8888);
pm.setColor(type.getColor());
pm.fill();
this.pm.setColor(type.getColor());
this.pm.fill();
this.solid = new Texture(pm);
this.region = new TextureRegion(solid);
createBody();
@ -196,6 +196,18 @@ public class Brick extends Entity implements PhysicsBody, CollisionListener {
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
public void dispose() {
solid.dispose();

View File

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