Using Trackers


~*!!!IMPORTANT!!!*~
To make use of the code below you will need to download this ProjectileTracker and place it into your project, not the one that was in Pong.

Understanding Trackers

That's how to use a tracker, but how do they work? They really are not terribly complicated. Look at the ProjectileTracker.java to download at the top of this page and find the advanceTime method in it. It is really quite simple: update the current translation based on the velocity and the time that has passed and also rotate (if necessary). velocity*timePassed yields a distance moved for the amount of time that has passed, which is something you have learned or will learn in physics. The other important method is getTranslation( ), which returns the current translation of the tracker. So, behind the scenes, when FANG is drawing a new frame, first advanceTime gets called on all trackers so that they update their translations. Next, it calls getTranslation on all of them and moves their associated sprites by that amount. It uses the translation to move a sprite the tracker is associated with the same way we learned to move a sprite by using "sprite.translate( deltaX, deltaY );"


Bouncing is a little more complicated and depends on finding the surface normal of the surface you are bouncing off of. This can be easy (for say a rectangle) or complicated (a circle). Once you know this normal, bouncing is a matter of reflecting the vector of the bouncee's motion around this normal and sending the bouncee off in this reflected vector's direction. Hard to explain without a picture. I'd try searching the internet if you want to know more.

Writing a Tracker

If you want to try writing your own tracker you can try this FANG tutorial. You can either make a new project and try the code or just read through it. Note that the wiki's code has "package Jam.firsttracker;" and "import wik.Wiki;" up at the top. You need to change the package to whatever package you're creating and remove the "import wiki.Wiki;" line before your code will work.