by Jon (Updated on 2014-12-04)
- What are Backgrounds?
- How do Backgrounds scroll? (Parallax Scrolling)
- How To: Importing Backgrounds
- Animated Backgrounds
- Repeating Backgrounds
- Backgrounds in the Scene Designer
- Custom Scroll Factors
What are Backgrounds?
Backgrounds are large images that usually scroll alongside a scene, either entirely behind or in front of a scene.
Backgrounds can visually enhance a game and provide the illusion of depth. Some games even draw backgrounds in front of a screen for visual flair (like in the video above) or to obscure part of the screen.
How do Backgrounds scroll? (Parallax Scrolling)
Put simply, backgrounds scroll at the same pace that you progress overall inside a scene, where "progress" is defined by the location of the Camera. This is commonly known as Parallax Scrolling.
If you’re halfway through a scene, the background will be scrolled halfway through.
Likewise, if you're at the end of the scene, the background will be scrolled through to the end.
To think about this another way, since backgrounds are almost always larger than the screen size, they’ll scroll at a slower-pace than the main layers, making them feel like they’re in the distance.
In this video, notice how things in the "foreground" scroll by quickly while things in the "background" (hills) scroll by slowly.
Intuitively, this makes sense. If you look outside your car's window, the close-by buildings you drive by will fly by quickly. But the mountains in the distance will move relatively slowly because they are far away.
How To: Importing Backgrounds
Importing backgrounds works much like importing any other kind of graphic into Stencyl.
1) Create a new Background.
2) Inside the Background Editor, Click the dotted box to choose an image or drag and drop the image in.
3) Once you've done that, click the Attach to Scene button at top-right corner to attach this background to a Scene. That's it!
You may notice that you can import multiple frames into a background and edit each frame's individual duration. Doing this will cause the background to animate.
Some games call for a background that automatically scrolls, regardless of the player’s progression through a scene. Auto-scrolling can impart the sense of constant motion.
Setting a background to auto-scroll is simple.
The values don’t hold much meaning in themselves (pixels per sub-frame). Just experiment until you get a value that works for your game.
Note that auto-scrolling backgrounds do not parallax scroll - they're already scrolling!
What if your background is meant to be a repeating pattern like the following?
Mark the Repeat Background checkbox if this is the case.
Repeating Backgrounds can auto-scroll, but they do not parallax scroll. In other words, they scroll directly alongside the main layers.
Backgrounds in the Scene Designer
Starting in Stencyl 3.2, backgrounds are treated as regular layers, so they are are managed through a Scene's Layers pane. This contrasts with our prior approach, which managed backgrounds separate and only allowed them to exist above or below regular layers.
To add a background, click on the + icon at the bottom of the Layers Pane (pictured above) and pick New Background Layer.
After adding a background, you can customize a few properties by clicking the cog icon at the right. These properties include its name, opacity and blend mode as well as parallax scroll factors.
Custom Scroll Factors (for Backgrounds and Layers)
As described earlier, backgrounds scroll in parallax. This means that they scroll at the same pace that you progress overall inside a scene. For example, if you’re halfway through a scene, the background will be scrolled halfway through.
For some games, this standard behavior isn't desirable, and for visual effect, the author wants the scrolling to happen faster or slower than normal, or in some cases, for the layer not to scroll at all.
To do this, you must customize the Scroll Factor for a layer from a Background's properties popup.
By default the Scroll Factor is 1. Switching it to 2 will double the amount of scroll that is done, while switching it to 0.5 will halve it. Switching it to 0 will stop scrolling entirely for that laye
- Backgrounds are large images that scroll behind or in front of the screen.
- Backgrounds are like mountains in real life - they scroll by slower than what’s happening right in front of you.
- Use auto-scrolling to make a game feel like it’s in constant motion.
Challenge: Endless Game
Endless games such as Canabalt and Jetpack Joyride are very popular these days.
Even Stencyl has its own variation on this theme in the form of Super Belly Boarder, a winter-themed take on an endless game.
Create a simple endless game of your own, using an auto-scrolling background to impart the illusion of constant motion.
Think carefully about how you’d make the game truly endless and random in nature. In other words, don’t make an enormous level - that’s the wrong way to do it.