So far in my game, I’m using 8 layers in the main scenes, including the default base layer: One for the tilemaps, one for hidden objects (collision objects for the tilemap), one for animations (I set the base layer time scale to 0 for those), one for dialogue text, one for text while reading a sign, one for screen fades/reveals, and one for the UI.
The game uses a screen-by-screen camera movement style using the lerp function, like in the 2D Zelda games.
What I’ve been noticing when testing things out is that the UI layer stays on camera with the base layer all the time, which is what I want. However, when I change screens and the camera scrolls, then I try to move the player to the Animations layer or try to play an animation on the Screen Transitions layer, they aren’t showing up. So I moved the cameras of those layers to move with the base layer, and now the things on those layers show up as intended. I’m rather confused by the whole layers/cameras thing now.
My question is, why did I have to move the cameras for those two layers to match the current camera position of the base layer and able to see the animations on them, while I’ve never moved the camera of the UI layer or the Sign Text layer yet they “follow” the camera of the base layer?
In other words, why does it seem I’m having to move the cameras of certain layers and not the other layers to get everything to show up properly on any screen that the base layer’s camera has been moved to? Why can’t I just leave all the layer cameras alone and get them to “follow” the base layer camera like the UI and Sign Text layer cameras are?
Thanks in advance for your information. This is something I feel like I really need to get a better understanding of going forward!
Positions are absolute, and shared across layers.
Here’s an example:
- Your game resolution is 1920x1080
- You have an object at 0,0 on the base layer
- You have two other layers, one for UI, one for Testing. You are not moving those layer’s cameras.
- At the start of the scene, everything is at the same point, so all of the layer camera centers are at 960x540.
- You then move your object to 5000x1000
- You have your camera follow the object after it moves, so the center of the base layer camera is now 5000x1000.
- You then move the object to your Testing layer.
- The object is still at 5000x1000. However, you have not moved your testing layer’s camera at all. So it is still at it’s starting position, 960x540. The object is on this layer correctly, but it is multiple screen width’s to the right past the camera’s position, and therefore will not show up since you never moved that layer camera over.
Thank you for your explanation. It made me think of something else I forgot to add in my original post.
I position all the objects on the UI layer and Sign Text layer using code, with global variables to control their positions. Since I’m doing this for those two layers, is that the reason why I’m not having to move those layer cameras to get the objects to pop up on screen (using Show Layer action) regardless of what screen I’m on?
Because otherwise, if the player object moves over one screen to the right, shouldn’t the UI layer camera stay in its original position just like the Animations and Screen Transition layer cameras do? It doesn’t though…it stays where it is supposed to at the top of the screen regardless how many times I scroll the screen and move the base layer camera, even though it’s on the UI layer.
I don’t know why I’m having so much trouble wrapping my head around this, and I appreciate any further explanation you can give!