Use instance bodies array

This commit is contained in:
Matt Low 2018-11-15 14:48:32 +04:00
parent adebc42c16
commit 9eac3353b6

View File

@ -61,6 +61,8 @@ public class PlayState extends State {
// Initialize a world with no gravity // Initialize a world with no gravity
world = new World(new Vector2(), false); world = new World(new Vector2(), false);
world.setContactListener(new Box2dContactListener()); world.setContactListener(new Box2dContactListener());
bodies = new Array<Body>();
// define a playArea body with position set to 0 // define a playArea body with position set to 0
BodyDef playAreaDef = new BodyDef(); BodyDef playAreaDef = new BodyDef();
@ -117,7 +119,6 @@ public class PlayState extends State {
@Override @Override
public void render() { public void render() {
Array<Body> bodies = new Array<Body>();
world.getBodies(bodies); world.getBodies(bodies);
for (Body b : bodies) { for (Body b : bodies) {
Entity e = (Entity) b.getUserData(); Entity e = (Entity) b.getUserData();
@ -207,9 +208,10 @@ public class PlayState extends State {
@Override @Override
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
world.dispose(); world.dispose();
bodies.clear();
powerUps.clear(); powerUps.clear();
powerUps = null; powerUps = null;
balls.clear(); balls.clear();