4. Inheritance: Making the globe do what we want

The globe HERE is quite cool. It does a few things:

1. it rotates automatically

2. you can click and drag it around

3. if you stop dragging it, it just stops

4. little 'pings' pop up randomly

We want to change some of these things, but leave some of them the same. In computing, this is called 'inheritance'. When we make a new or different version of an object, we keep things the same unless we tell the program to change them.

So instead of the 4 things above, we want to:

1. not rotate automatically

2. drag it around, but just horizontally

3. when you let go, it carries on spinning, and eventually stops

4. when it stops, make it highlight a country.

When I'm programming stuff, some things are easy, or quick, and some things can be very hard!

Number 1 was easy. There was some code to 'autorotate'. It was set to start at the beginning, pause when you drag the globe, and start again when you let go. I just removed the code, done!




Number 2 was ok too. There is a bit of maths that works out how you have moved your mouse or finger, and works out how to rotate the globe. Luckily it works it out separately for the x-axis (left to right) and the y-axis (up and down). All I had to do was make sure only the x-axis changed. I just had to change one line of code, like this:

rotation[1] -= degY;

rotation[1] = -10;


You can see the progress so far if you CLICK HERE.

Also, I've left a hidden message for you on the website. To see it just click F12 on your keyboard. This is one way coders check things on their websites. Make sure you're on the CONSOLE tab, then spin the globe to read the message. You might like to look at the other tabs too.

The other things on my list are going to be a bit harder...


Comments