Adding a Compass (draft)

Shows how to add an interactive compass UI to the map.

How to add a compass

To test the compass you can rotate the map via a and d.

compass

Simple

Check out the SimpleCompassApp.java.

To add a compass you only need the compass object

CompassUI compass;

initialize it in your setup()

compass = new CompassUI(this,map);

and draw it in your draw()

compass.draw();

Thats it, easy peasy.

Advanced

We have also a more complex constructor for you, to make various changes like display a custom compass image. ComplexCompassApp.java

public CompassUI(PApplet p, AbstractMapDisplay mapDisplay, PImage img, float x, float y)
  • mapDisplay: your mapDisplay
  • img: the PImage you want to use as a compass
  • x: absolute x
  • y: absolute y

To change the compass image you need to initialize a new PImage and initialize the compass with it:

PImage compassImg = loadImage("compass_grey.png");
compass = new CompassUI(this, map.mapDisplay, compassImg, 700, 100, 1);