Join Jesse Freeman for an in-depth discussion in this video Building a repeating background, part of Unity 5 2D Essential Training (2015).
- So now that our camera is automatically set up to resize itself based on the resolution of the game, we can go in and start building out the level for our game. Let's select all these items that we were testing with, and delete them from the hierarchy view. Also, we'll wanna set the camera back to size 80. This way, when we're laying things out, we'll be able to see them in the game preview. For now, we'll leave it at 1024 by 768. You'll see that we're usimg a resolution of 360 by 270 because my monitor is a little bit smaller.
If I was to increase this or decrease this, you would see a larger resolution size. Likewise when you're testing, you could do "maximize on play" to see the full screen. So in order for us to do the background, we're gonna need to go back into our artwork folder, and take a look at our texture. Let's start with the wall texture. Now by default, this was imported as a sprite. Here we're gonna convert this back into a texture. Then, what we can actually do is modify the wrap mode, to allow it to repeat.
We still wanna change the filter mode to "point," and we can go back to the format and we can set this to "True color," and hit "Apply." Now our texture will repeat whenever we add it to a surface. In this case let's create a simple game object that will allow us to apply the texture and represent our background. We'll go to the GameObject menu, we'll go to the 3D list, and we'll create a quad. Now, the quad is gonna be really small because the pixels to units in our game are so high.
If we double click on our quad and zoom in, you'll take a look at what this is. It's very similar to a plane, but it's actually comprised of two triangles. If we were to go into 2D mode, you would see that the quad disappears because there's no background texture for it. Now, I like to use quads because one, they're very efficient, and two, they allow me to do things like resize them and scale them, and give me a large surface to attach artwork to.
Especially a background in a 2D game. Now, let's change this quad to match the size of the texture we're gonna apply to it. We're gonna go over to its scale and set this to 32 by 32. Again, if we double click on the quad in the hierarchy, we'll zoom out. And here you'll get a good estimate of what this is looking like in our game. Next, we're gonna wanna change the Z of this object, to be a little bit further away from the camera. Now, when we work in the 2D part of Unity, we don't actually have to worry about Z.
But because this is a 3D object, and we're gonna add a few different quads over the next few videos, we wanna make sure that they're layered correctly. In this case, we're gonna set it to two, which will push it further away from the camera. To give you a point of reference, if you look at the camera, the Z index for the camera is set to negative 10. Now, back on our quad, you'll see it looks kind of boring. Now, in order for us to actually apply a texture to it, we're gonna have to create something called "the material." In our "Assets" folder, let's create a new folder called "Materials." And inside of "Materials," we're gonna create our first material.
Let's call this "wall texture." Now for the point of this course, we're just gonna pick a very simple "shader," that will help us render the texture in a way that will let us repeat the background. "Shaders" alter the way the materials look in the game. In this case, we're simply gonna go the "Mobile," "Particles," "Alpha blended." And you'll see the options have now changed based on the shader that we're using. Here we can select a texture. We'll hit the "select" button, and we'll scroll down and we'll find our wall texture.
Now we have our wall texture set. If we were to drag this wall texture over to our quad, you'll now see that our wall texture appears in the background. In the next video, we'll talk about how tiling works, and how to resize this, so that it fills up the entire screen.
Super Zombie Runner riffs off the popular endless runner genre: a one-button casual game that's not only fun to play but exciting to build. The focus of the work is a reusable code base that you can extend and make your own, while learning the basics of object pooling, supporting multiple screen resolutions, tracking scoring, and multi-platform publishing. Along the way, Jesse covers key Unity features, such as working with sprites, creating animations, and leveraging the UI components.
- Working with sprites and animation
- Creating the player
- Spawning GameObjects
- Adding obstacles and collisions
- Building the game objects and logic
- Managing game state
- Creating pixel-perfect cameras
- Designing for multiple screen resolutions
- Adding scores
- Optimizing performance
- Publishing to desktop, web, and mobile platforms