Game Development Reference
In-Depth Information
The applyTo() method should be called on each frame right at the beginning in
the renderTestObjects() method of WorldRenderer . It will take care of correctly
setting up the camera object that is passed.
You can now start the game on your desktop and try it out. To enable the camera
follow feature, simply press the Enter key to toggle the state. A message is also
logged to the console that informs you about the current state it is in. When the
camera follow feature is enabled, use the A , D , W , and S keys to move the selected
sprite. However, the difference now is that the camera is following you to every
location until the camera follow feature is disabled again.
The last change to the code deals with adding a lot of new keys to control the camera
in various ways.
Add the following code to WorldController :
private void handleDebugInput (float deltaTime) {
if (Gdx.app.getType() != ApplicationType.Desktop) return;
// Selected Sprite Controls
float sprMoveSpeed = 5 * deltaTime;
if (Gdx.input.isKeyPressed(Keys.A)) moveSelectedSprite(
-sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.D))
moveSelectedSprite(sprMoveSpeed, 0);
if (Gdx.input.isKeyPressed(Keys.W)) moveSelectedSprite(0,
sprMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.S)) moveSelectedSprite(0,
-sprMoveSpeed);
// Camera Controls (move)
float camMoveSpeed = 5 * deltaTime;
float camMoveSpeedAccelerationFactor = 5;
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) camMoveSpeed *=
camMoveSpeedAccelerationFactor;
if (Gdx.input.isKeyPressed(Keys.LEFT)) moveCamera(-camMoveSpeed,
0);
if (Gdx.input.isKeyPressed(Keys.RIGHT)) moveCamera(camMoveSpeed,
0);
if (Gdx.input.isKeyPressed(Keys.UP)) moveCamera(0, camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.DOWN)) moveCamera(0,
-camMoveSpeed);
if (Gdx.input.isKeyPressed(Keys.BACKSPACE))
cameraHelper.setPosition(0, 0);
 
Search WWH ::




Custom Search