This site requires JavaScript, please enable it in your browser!
Greenfoot back
Username45
Username45 wrote ...

2018/11/2

Error in Method Call. Why does space have to be infront of gameOver if the game over method is public

Username45 Username45

2018/11/2

#
         Asteroid a = (Asteroid) getOneIntersectingObject(Asteroid.class);
          if (a != null) 
         {
            Space space = (Space) getWorld();
            space.addObject(new Explosion(), getX(), getY());
            space.removeObject(this);
            
            space.gameOver();
        }
    }
danpost danpost

2018/11/2

#
Username45 wrote...
Error in Method Call. Why does space have to be infront of gameOver if the game over method is public
Because without it, "this" (the bullet, I presume, in your case), by default, is the object that the gameOver method would be executed on. But, the method is in your Space class and belongs to instances of the Space class. "public" just means you can call the method on an instance of the class from another class. From another class, you need to specify which instance of the class you are calling the method on, noting that you can create multiple instances from a single class.
You need to login to post a reply.