As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

99,874

Views

Beginner

Level

15

Comments

The Camera

by Jon (Updated on 2015-10-20)


Contents

  • Introduction
  • Scrolling
  • Example: Making the Camera Follow the Player
  • Moving the Camera
  • Off Screen Actors Become Inactive

Introduction

In this article, we introduce the concept of the camera and describe how you can make games scroll using the camera.

Scrolling

Although some games exist entirely on a single screen, many extend beyond that. For example, think about a game similar to Super Mario Bros. Levels extend beyond a single screen.

In games like these, when the player walks to the right, the game “scrolls” to the right.

How does this “scrolling” work? In simple terms, scrolling is the act of changing what part of the scene is visible.

One can draw a connection to something we’re familiar with - peering through the viewfinder (or screen) of a camera to compose a photograph.

The “camera” in our engine is the exact same concept - it’s the “thing” that controls what part of the scene is visible.

Note: In fact, the “camera” is an actor! It’s an invisible, non-physical actor, but like any kind of actor, it has a position and it can be moved around.

Example: Making the Camera Follow the Player

In many games, the camera follows the player, so that the player is always on screen.

This turns out to be trivial to accomplish since we have a “camera follow player” block as well as a pre-defined Behavior that you can attach to any scene that does the same thing.

Moving the Camera

The camera can be moved in 2 different ways, both which involve these blocks (under Scene > View > Camera).

Camera Blocks

Method 1: Set the Position

Move the camera to a specific (x,y) position inside the scene.

Method 2: Move to Actor

This will set the camera’s position to the center point of the Actor.

Note: One question you may have is: what if I make the camera go outside the scene’s boundaries? It turns out that the camera is locked to those boundaries and won’t head beyond them.

Off Screen Actors Become Inactive

Something you may notice is that actors that are off screen stop working, as if they froze in time. We do this to preserve performance.

Nevertheless, there are cases where you want an actor to be active regardless of whether it’s on or off screen.

To make an actor always active, use the following block (under Actor > Properties > Misc).

Summary

  • Scrolling is controlled by the camera.
  • The camera is a special kind of actor. It has a position and can be moved around.
  • Off screen actors become inactive. Use the “always simulate” block to override this.

Challenge 1: Auto-Scrolling

In some platformers, levels can auto-scroll. The player has no control over the camera.

How do we accomplish this effect given that you only have control over setting the camera’s position?

One approach is to make a dummy actor that controls the camera (by having the camera continually follow this actor).

By controlling this dummy actor, you gain complete control over the camera and can do more with it, such as panning it towards a destination over a time period.

Your challenge is this: Create a game that implements auto-scrolling.

Once you’ve got a simple auto-scrolling behavior completed, extend it so that once it reaches its first destination, begin auto-scrolling to the next one. Generalize this to work with an arbitrary number of destination points.

After that, figure out a way to prevent the player from exiting from the left/right sides of the screen. If you play any Mario game, you’ll notice that there’s an invisible wall that pushes you along should you try to exit the sides of the screen.

Challenge 2: Grid-Based Camera

Retro games have seen a resurgence in the past few years. To complete the retro feel of these games, some developers go to great lengths to preserve the precise, “8-bit” feel of these games.

Your task is this: create a retro-feeling camera that locks to the scene’s grid.

Instead of smooth, continuous motion, the camera only assumes positions that are multiples of the tile size. Create a game with this kind of camera motion.

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

15 Comments

bigmike123
now i want to play super mario
1 11 years, 2 months ago
patrickjavier
UN WORKING:(!!!!

1 11 years, 5 months ago
lawgo
I'm so pleased that it's amazingly easy to implement camera follow. Huzzah!
0 12 years, 4 months ago
jwjb
The first video "Super Mario World - The Lost Lands: Pipe Caverns 1" is marked private and cannot be viewed.
2 12 years, 4 months ago
darkknighth20
Thanks for this guide!

I ran into an issue where the "Actor is on Screen" function kept counting me as not being on the screen when my actor was barely off the screen.

To remedy this, I used the function 'set offscreen bounds to' lower the sensitivity. Hopefully this helps someone else!

3 12 years, 8 months ago

Sign In to Comment