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

2015/4/2

Location

MrGigglesII MrGigglesII

2015/4/2

#
How can I make a class that extends another class turn towards that other class. I've tried this (but it gives me an error saying there isn't a character of that class in the world get):
public int x = getX();
public int y = getY();
danpost danpost

2015/4/2

#
Please elaborate. It may be that the one class should not extend the other. Say you have a ClassA and a ClassB. If you cannot say a ClassB object is a type of ClassA object, then ClassB should not extend ClassA. For example, if I had a Car class, I can extend it with Sedan, Coupe, and Wagon (these are types of cars); but I should not extend it with Bicycle, WindShield or Truck (these are not cars). However, with the code provided, it looks like you are trying to set field values 'x' and 'y' by calling a method that requires the actor be in the world. These fields are created and assigned their values (or at least an attempt is made to assign its value) at the time the actor is created and the actor must be completely created before it can be placed into a world when 'getX' and 'getY' finally would be able to be called without error.
You need to login to post a reply.