31,665

Views

Beginner

Level

11

Comments

The Camera

by Jon (Updated on 2012-03-30)


Contents

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


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 all 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:

  1. Set the camera’s (x,y) position.
  2. Make the camera follow an Actor. This will set the camera’s position to the center point of the Actor. Unlike the name suggests, this is a one-off move that must continually be used to continue the “following”


(Scene > View > Camera)

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 “simulating”, 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.


(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.

Disclaimer: All articles are geared towards Stencyl 3.0 and above. 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!

11 Comments

Cesco
Excellent tutorial!
0 1 month, 2 weeks ago
z26
cheesynoddle: I'm not sure, but a possible workaround would be to rotate every game object (therefore the whole game world) around a set point. Not the most elegant solution, I must admit.
0 3 months, 3 weeks ago
cheesynoodle
Is there any way to rotate the camera? I'm interested in tilting it, or turning it upside down.
0 4 months, 1 week ago
liteking
It should be noted that "Move Camera to x, y" means the CENTER of the camera will focus at x, y. Not the Top Left corner of the camera.
0 4 months, 4 weeks ago
liteking
You need to attach the Camera Follow to the player character actor
1 6 months, 6 days ago
miamidwade3
i downloaded "camera follow player" from stencyl forge and i also tried "smooth camera" and none of these work . it usually ends up not following the character
0 6 months, 2 weeks ago
bigmike123
now i want to play super mario
0 10 months, 2 days ago
patrickjavier
UN WORKING:(!!!!

1 1 year, 1 month ago
lawgo
I'm so pleased that it's amazingly easy to implement camera follow. Huzzah!
0 2 years, 2 weeks ago
jwjb
The first video "Super Mario World - The Lost Lands: Pipe Caverns 1" is marked private and cannot be viewed.
1 2 years, 3 weeks ago

Sign In to Comment