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

2016/3/20

System.out.println stops my game.

MNic MNic

2016/3/20

#
As I tried to make a Arkanoid game I stumbled upon a problem. I tried to check what the X is of actor brick with the following line of code.
public void hit()
   {
       Actor brick = getOneIntersectingObject(brick.class);
       
       if(brick != null)
       {
           System.out.println("We got brick!");
           getWorld().removeObject(brick);
           System.out.println(brick.getX());
        }
The game stops working and doesn't show brick.getX() in the terminal window
danpost danpost

2016/3/20

#
The first time the terminal is opened (being used), the focus is transferred to it. You only need to change the focus back on the scenario. Just click on the greenfoot application frame. You can avoid this on future prints by not closing the terminal. You can hide the terminal instead of closing it or just leave it open.. As far as not printing the x-coordinate, you should be getting an IllegalStateException error due to the fact that you are trying to use 'brick.getX' when the actor is not in the world (the previous line removed it from the world).
You need to login to post a reply.