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.

Healthbar and percentages

Healthbar and percentages - JavaScript Tutorial

From the course: Game Development Foundations: Game-Related Math

Start my 1-month free trial

Healthbar and percentages

- [Narrator] For our first formula example, we're going to take a look at how to draw a health bar. This is a common question I get a lot when people are starting out to make games, and that's how do you simply display the player's health on the screen? To get started, let's go into our Example Files folder and open up Chapter Three. Then open up 03_01 and the Start folder. Inside of here you'll see the health example js file. Double click on this, and open it up in your text editor of choice. We'll select all the code, copy it, and go over to Codepen. Let's create a new pen, and we'll call this Health Example. Next, we'll double click on the JS tab in order to expand it and paste our code in. Once the preview shows up, simply drag the middle bar over the right to give us more room. As you can see, we've already set up the example for our health. We have two bars that are being drawn on top of each other. The first is a black bar that represents the background of the health bar. The…

Contents