particles

HTML5 game development blog

<!-- a HTML5 game development blog -->

Pages

twitter account

Monday, July 22, 2013

Tutorial 3 - Dragon of Bosnia: Classes in JavaScript - Making a Loading Bar Class

So this tutorial is on classes, I guess you know that they are quite important when it comes to programming and i hope you know what they are already, but we will do a little recap, so we can move on confidently to the game programming stuff. We will also make a class out of our loading bar from the previous tutorial so we can change it quickly to our liking.

Short introduction to classes and objects
When i learned about classes in school i remember that in a textbook they where explained with an example using cars. I guess that's good everything explained using cars is quite understandable, we all know cars. But I am bad at drawing cars so I will use trees instead to explain the concept. 

We know what trees are, they are big, they grow, have leafs and we can chop them down and make furniture. So that are the basics of being a tree but there are all sorts of them out there, a tree can be a oak, a pine or a palm tree which are all quite different but have the same basic properties in common like the having leafs thing and being chopped down for furniture. 

So our Tree class would be a basic concept a template of sorts of what a tree is with it's properties and methods, and we can use our Tree class to create specific tree objects (or instances) like a pine tree or a palm tree which are different from one another in some of the properties but both are still trees and inherit from our class.

Trees