Game Development Reference
In-Depth Information
We have to make some minor changes to the
CameraHelper
class in order to make
the switch from using
Sprite
objects to
AbstractGameObject
.
Remove the following import line from
CameraHelper
:
import com.badlogic.gdx.graphics.g2d.Sprite;
Next, add this import line in
CameraHelper
:
import com.packtpub.libgdx.canyonbunny.game.objects.
AbstractGameObject;
Now, change the code in
CameraHelper
:
private AbstractGameObject target;
public void update (float deltaTime) {
if (!hasTarget()) return;
position.x = target.position.x + target.origin.x;
position.y = target.position.y + target.origin.y;
}
public void setTarget (AbstractGameObject target) {
this.target = target;
}
public AbstractGameObject getTarget () {
return target;
}
public boolean hasTarget (AbstractGameObject target) {
return hasTarget() && this.target.equals(target);
}
Next, add the following code in
WorldRenderer
:
private void renderWorld (SpriteBatch batch) {
worldController.cameraHelper.applyTo(camera);
batch.setProjectionMatrix(camera.combined);
batch.begin();
worldController.level.render(batch);
batch.end();
}
Then, remove the
renderTestObjects()
method from
WorldRenderer
.