0% found this document useful (0 votes)
10 views8 pages

Game Camera

The document provides an overview of camera types used in computer games, detailing eight basic types including fixed point, rotating, scrolling, movable, floating, tracking, pushable, and first person. It emphasizes the importance of the three Cs of game development: camera, character, and control, which are crucial for player engagement and understanding of the game world. Additionally, it includes code examples for creating a Camera class in a game development context, illustrating how to implement camera functionality in a game environment.

Uploaded by

Nyawira Dee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Game Camera

The document provides an overview of camera types used in computer games, detailing eight basic types including fixed point, rotating, scrolling, movable, floating, tracking, pushable, and first person. It emphasizes the importance of the three Cs of game development: camera, character, and control, which are crucial for player engagement and understanding of the game world. Additionally, it includes code examples for creating a Camera class in a game development context, illustrating how to implement camera functionality in a game environment.

Uploaded by

Nyawira Dee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

LESSON FIVE: SETTING CAMERA

Camera in computer game


A camera is a player’s vantage point in a game, her eye into the world. The vast majority of games
use one or more of eight basic types.

Camera Types

1. Fixed Point: A fixed point camera neither moves, scrolls nor rotates. Many simple games like
Tetris or Bejewelled use one fixed point. Larger games like Jet Set Willy use a series of fixed point
cameras, one for each room. Adventure games like Blade Runner also use some fixed point
cameras, but the perspective differs from scene to scene.
2. Rotating: A rotating camera is unable to move or scroll but it can turn. Adventure, platform and
survival horror games sometimes use rotating cameras for especially grand rooms. An alternative
use is for tight spaces in some otherwise tracking-based games (see below), or for special modes.
3. Scrolling: The game world is a flat two dimensional grid and the scrolling camera moves on a
plane parallel to it. Scrolling cameras can move horizontally, vertically, or both depending on the
game. Many 8-bit and 16-bit platform games use scrolling cameras, as do shooters.
4. Movable: Sim and strategy games often use a movable camera. The player looks down from
overhead and moves the camera around the world using arrow keys or the mouse. Some games, like
World of Goo or Angry Birds, use the same kind of camera but look from the side rather than
above.
5. Floating: Floating cameras are movable cameras with no fixed orientation. The floating camera
adds rotational control allowing full 3D navigation. The Total War games, Black and White and the
Homeworld games use floating cameras.
6. Tracking: This camera tracks the doll along a pre-defined line in 3D space. It may rotate, speed
up or slow down, fall behind or even move ahead of the doll as required but the player has little or
no control over its movements. Tracking cameras are often used in linear action or platform games
like God of War or the Kim Possible DS games.
7. Pushable: Pushable cameras occupy a default position (usually behind the doll) when not
controlled, but the player can push them using a second thumb stick or mouse. The camera then
rotates around the doll. This kind of camera is very common in modern games. Pushable and
tracking cameras are often casually grouped as ‘third person’ perspective.
8. First Person: First person perspective combines the camera and the doll, which means the player
sees through the doll’s eyes. He uses one set of controls to move the doll’s body and another to turn
its head. One limited variant of first person perspective is the bonnet camera in some racing games.
Another is sniper mode, where the player can aim but not move (or not move well).
THE THREE Cs OF GAME DEVELOPMENT
When you make a game, keep in mind the three Cs of game development:
1. camera,
2. character, and
3. control.
• These three Cs act as the player’s main introduction into the world that you hope to create.
• They’re the only aspects of your game that your player will always be dealing with.
• When you understand the role of each of these three Cs in your game, you’ll better
understand not only your game, but all games that you create or play.

CAMERA
• The camera is the player’s window into your game. It’s what the player sees and responds
to. Camera placement in a game is vital because the player’s basic understanding of your
game world will come through the camera.
• Changing the location of the camera can change the entire feeling of the scene or, in some
cases, break the scene entirely.
• Your game camera should be treated in much the same way as a film camera. The problem is
that, in games, you can’t always control where the player (or camera) goes.
• When you create your camera, you have to decide how much control you want your player
to have over the camera and whether you’ll limit that control in any way.
• Cameras that players have complete control over or that players can rotate reveal to the
player information from all over the world

CHARACTER

• The character is who the player is playing as in the game.


• This can be deceptive because the theme of the character doesn’t matter at this point in game
development. Whether the character is a super-detailed soldier or a box is irrelevant when
you’re coding your game.
• What you need to think about when you think of character is what exactly your character
does within the game.
Ask yourself the following questions:
i. Does the character jump? If so, how high?
ii. Does the character have four-directional movement (forward, backward, left, right) or does
the character only move forward and backward?
iii. Does my character have any weapons or tools? If so, what are they?
• How your character moves not only changes what your game is but how you’ll go about
coding your game.
• A first-person shooter has an entirely different code than a platformer.
• Even different types of platformers can have a variety of different codes simply because of
the types of controls you want the character to have.

CONTROL
• Control is how your player interacts with the game.
• The thing that separates games from every other type of entertainment medium is their
unique ability to engage with an audience.
• Players don’t just read or watch the events play out as they do with books, movies, or TV
shows.
• They play an active role in the experience and are invested in the characters because they are
the characters.
• Controls make or break a game. A game with a poor control setup will never engage players
on the same level as one with good controls, no matter how good the graphics or story is.
• You play games because they make you feel in control, so when you design your game, you
have to think about how controls interact with the player and how you can make the game
accessible for the greatest number of people or example, when you think about movement in
a computer game, what buttons do you think of?
• Probably the W, A, S, and D keys. But why? Why don’t gamed designers use the 6, Caps
Lock, Enter, and Spacebar keys instead? After all, those keys also relate to the different
directions.
• The reason designers typically use W, A, S, and D is because they don’t want the player to
have to put a lot of effort into playing the game for each desired effect.
• If you have to move your hand too much, or stop and think about the controls, that can break
your immersion in the game, which kills it.

Lets create a new Camera class in the window package with a


constructor and getters and setters as shown below.

Step 5.1

package com.embu.gamedev.window;

import com.embu.gamedev.framework.GameObject;
public class Camera {

public Camera(float x, float y) {


this.x = x;
this.y = y;
}

public void tick(GameObject player){

private float x, y;

public float getX() {


return x;
}

public void setX(float x) {


this.x = x;
}

public float getY() {


return y;
}

public void setY(float y) {


this.y = y;
}

Step 5.2

Then go to the Game class and initialize our Camera class.

Add the object cam as shown below

Camera cam;

modify the init() method in Game class as shown below.

public void init() {


WIDTH = getWidth();
HEIGHT = getHeight();
handler = new Handler();
handler.addObject(new Player(100, 100, handler, ObjectId.Player));
handler.createLevel();
cam = new Camera(0, 0);
this.addKeyListener(new KeyInput(handler));
}

Modify the tick() method in Game class as shown below.

private void tick() {


handler.tick();
for (int i = 0; i < handler.object.size(); i++) {
if (handler.object.get(i).getId() == ObjectId.Player) {
cam.tick(handler.object.get(i));
}

}
}

To activate our camera we will use Graphics2D

Graphics2D g2d=(Graphics2D)g;

g2d.translate(cam.getX(),cam.getY()); //Start

handler.render(g);//everything rendered will be captured or affected by camera

g2d.translate(-cam.getX(),cam.getY()); //end

Step 5.3

The Game class will be modified to

package com.embu.gamedev.window;

import java.awt.*;
import java.awt.image.BufferStrategy;
import java.util.Random;
import com.embu.gamedev.framework.GameObject;
import com.embu.gamedev.framework.KeyInput;
import com.embu.gamedev.framework.ObjectId;
import com.embu.gamedev.objects.Block;
import com.embu.gamedev.objects.Player;

public class Game extends Canvas implements Runnable {

private static final long serialVersionUID = -8360998378314880919L;


private boolean running = false;
private Thread thread;
static int WIDTH, HEIGHT;

Handler handler;
Camera cam;

Random rand = new Random();

public void init() {


WIDTH = getWidth();
HEIGHT = getHeight();
handler = new Handler();
handler.addObject(new Player(100, 100, handler, ObjectId.Player));
handler.createLevel();
cam = new Camera(0, 0);
this.addKeyListener(new KeyInput(handler));
}
public synchronized void start() {

if (running)
return;

running = true;
Thread thread = new Thread(this);
thread.start();

public void run() {

init();
this.requestFocus();

long lastTime = System.nanoTime();


double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while (running) {
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while (delta >= 1) {
tick();
updates++;
delta--;
}
render();
frames++;
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("FPS: " + frames + " TICS: " +
updates);
frames = 0;
updates = 0;
}
}
}

private void tick() {


handler.tick();
for (int i = 0; i < handler.object.size(); i++) {
if (handler.object.get(i).getId() == ObjectId.Player) {
cam.tick(handler.object.get(i));
}

}
}

private void render() {


BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}

Graphics g = bs.getDrawGraphics();
Graphics2D g2d = (Graphics2D) g;
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
g2d.translate(cam.getX(), cam.getY()); // Start
handler.render(g);
g2d.translate(-cam.getX(), cam.getY()); // end
g.dispose();
bs.show();
}
public static void main(String args[]) {
new Window(800, 600, "Embu Games Prototype", new Game());
}
}

Step 5.4

We can now test the Camera by updating the tick() method in Camera class as
below

public void tick(GameObject player){


x=-player.getX()+Game.WIDTH/2;
}

The updated Camera class will appear as below

package com.embu.gamedev.window;

import com.embu.gamedev.framework.GameObject;

public class Camera {

public Camera(float x, float y) {


this.x = x;
this.y = y;
}

public void tick(GameObject player){


x=-player.getX()+Game.WIDTH/2;
}

private float x, y;

public float getX() {


return x;
}

public void setX(float x) {


this.x = x;
}

public float getY() {


return y;
}

public void setY(float y) {


this.y = y;
}

When you execute the project our screen will start to move to the left.

You might also like