Dragonfly Q&A

When world is populated, Saucer sprite is stuck in the upper left-hand corner of screen.

0 like 0 dislike
When I press "p" to begin game, the game begins with a saucer sprite stuck on the upper left-hand corner of the screen. I've been trying to solve this for a while now, unsuccessfully. The interesting part is that about 50% of the time, the sprite moves after a few seconds, while in the other 50%, the sprite is just stuck there.
asked Sep 3, 2014 in Tutorial by rlangelo

1 Answer

0 like 0 dislike

This behavior happens if an Object is created on top of another solid Object (e.g., one Saucer on top of another).  When either Object tries to move, it will have a collision with the other and freeze.  In this case, they are "stuck" in the upper left corner since that is location (0,0).

The solution for the tutorial  is in the "End of Game" section of the tutorial:

"Once you spawn a lot of Saucers randomly, you may end up putting them on top of one another. In such a case, Dragonfly will generate a "collision" event and cause the Saucers to move back (to (0,0), by default). You'll want to add some code to the Saucer moveToStart() method to prevent this by inching the object to the right and checking with the WorldManager if there is a collision at the new location.

  // If collision, move right slightly until empty space.
  ObjectList collision_list = world_manager.isCollision(this, temp_pos);
  while (!collision_list.isEmpty()) {
    temp_pos.setX(temp_pos.getX()+1);
    collision_list = world_manager.isCollision(this, temp_pos);
  }
"
answered Sep 3, 2014 by claypool
Thank you for the answer. The bug is fixed. The problem was that I had this block of code after the call to the moveObject method.
More information about Dragonfly can be found on the Dragonfly Home Page.
...