From the course: Game Development Foundations: Game-Related Math
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Centering objects - JavaScript Tutorial
From the course: Game Development Foundations: Game-Related Math
Centering objects
- [Instructor] For our first example, we're going to learn how to center an object inside of another object. To do this, let's go into the chapter one folder inside of our exercise file folder. From here, let's open up 01_01, and then navigate to the start folder. Inside of this folder, you'll find the center-example.js file. Open up this in your text editor of choice. Once open, select all the code in this file and copy it. Now we're ready to move over to CodePen. Click on the create button and create a new pen. We'll start by renaming this pen center example, then we'll double-click on the JS tab in order to expand it and paste in our code. Once you've done this, select the center bar and give yourself a little bit more room to work with by dragging it over to the right. In this example, you'll see we have the border of our game screen as a black outline, and inside of it, we have a red box which represents our game's map, and then there is a smaller gray box in the upper left-hand…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.