How can I implement parallax scrolling with Paper2D?
I'm making a simple 2D game using Unreal's Paper2d sprites. My game is displayed in orthographic mode. Right now, I'm totally stuck on how to get parallax scrolling working on the background. I'm still pretty new to Unreal and I haven't really been able to understand other posts on the forums such as this and this on similar topics.
So far, all I really know is that I need to animate the background separately to the foreground, but I have no idea where to begin with that. Which Blueprints should I use? What events and functions should I use? I really have no idea. I was wondering if anybody could tell me a way to get parallax scrolling working, and explain it in a way that a beginner will understand? Thanks in advance.
asked Oct 09 '15 at 01:56 AM in Blueprint Scripting
Let's forget about blueprints and Paper2D for a moment and try to understand the concept of parallax scrolling. If we can't understand the concept, we have no hope of implementing it.
So, you have a character which can move left or right on the screen. Lets say that the character stays centered on the screen at all times. We want to show character movement by moving all other objects, relative to the character. So, if you walk to the left by 5 pixels, ALL other game objects should be shifted to the RIGHT by 5 pixels, right? So if you have a simple background, we move the background to the right by 5 pixels. This background has a 1:1 ratio to character movement. Let's call this background "Layer 0".
With parallax, we want to add a second background layer behind "Layer 0". This background layer is more distant, so it should move slower relative to the character movement. Perhaps we assign a ratio of 1:2. If the player moves to the left 5 pixels, this background layer moves 2.5 pixels to the right. Let's call this "Layer 1". We can simplify the amount the background moves as a fraction of player movement: 1/2
Maybe we add a third background layer, such as distant mountains. This is "layer 2", and we can give it a fractional movement amount of 1/3 or 1/4, whatever looks best.
Now, to implementation... your parallax backgrounds are really just large sprite textures with tiling. If you know how to load and move a sprite, you can implement parallax backgrounds :) I would tie the background movement to character movement events. Generally, you move the background relative to the character, but if the character reaches the edge of the map, you move the character instead of the map. I leave that part for you to figure out, it's pretty easy ;)
answered Oct 09 '15 at 02:17 AM
You might want to switch to Perspective view instead of Orthographic, and let the perspective do the work for you. Just lay out your background on the Y axis accordingly (if X and Z your horizontal and vertical axes). Because paralax effect actually IS caused by perspective, so instead of simulating it through blueprints, why not just let it work on the lower level?
Follow this question
Once you sign in you will be able to subscribe for any updates here