Dragonfly Q&A

Is there a bug with the reticle in the saucer tutorial?

0 like 0 dislike
I completed the reticle section of the saucer tutorial and I don't see the reticle on my screen.  I checked my code with the code from the game5.zip and they're exactly the same.  However, the reticle appears in the game5 project solution.  I can't figure out why the reticle is not working in my version of the game.  I know that Marco Duran is having the same problem, and I'm wondering if other people have experienced the same issue.  Is there a simple solution that we're not seeing?
Dragonfly version v4.0
asked Sep 1, 2015 in Tutorial by jpnelson

1 Answer

0 like 0 dislike

It may be that your Reticle object is not getting any events, particularly the mouse events that it needs.  Make sure:

  • The Reticle registers for interst in mouse events in the constructor (Reticle()):

  // Reticle moves with mouse, so register.
  registerInterest(df::MOUSE_EVENT);

  • Make sure the Reticle event handler method looks exactly the same as the parent Object handler (this is so the derived method is called).  It should look like:

int Reticle::eventHandler(const df::Event *p_e)

Note the "const" keyword, too.

If both those are right, add a LogManager writeLog() message at the top of the event handler just to see if it really is getting mouse events.

If it is, then the other issue may be drawing.  Check that the Reticle draw() method looks like:

// Draw reticle on window.
void Reticle::draw() {
  df::GraphicsManager &graphics_manager = df::GraphicsManager::getInstance();
  graphics_manager.drawCh(getPosition(), RETICLE_CHAR, df::RED);
}

Again, the signature needs to be matched or it won't get called. Again, at writeLog() messages to verify.

Hopefully, one of the above is your issue.  If you learn more in doing these investigations, post a follow-up comment.

answered Sep 1, 2015 by claypool
We figured it out.  In the tutorial it doesn't say to add a reticle to the Hero class.  We found code in the game5 project that adds a reticle in the Hero class and header.  In the Hero constructor should be:

  p_reticle = new Reticle();
  p_reticle->draw();

and a reticle variable needs to be added to the Hero header:

    Reticle *p_reticle;

It doesn't say to do this in the tutorial so this might become a problem for other people as well.

You are right!  I've added some instructions adding the necessary code to the online tutorial (http://dragonfly.wpi.edu/tutorial/) - the book will remain the same until the next version, of course. 

Thanks for pointing this out!

More information about Dragonfly can be found on the Dragonfly Home Page.
...