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

2022/7/7

change Image

luGGas luGGas

2022/7/7

#
I wanted to change the image of an object when the player scored more than 10 points. All classes are subclasses of the Player class. I wrote the following method in the player class and called it in the child classes and passed the correct image name as the transfer parameter:
public void changeImage(String name)
    {
        if(Score > 10)
        {
            setImage(name);
        }
    }
Als ich nun ds Spiel startete und 10 Punkte erreicht haben sich die Images der Unterklassen nicht verändert, nur das Image des Players, also der Oberklasse. Does anyone can help me?
danpost danpost

2022/7/7

#
luGGas wrote...
All classes are subclasses of the Player class.
That does not sound good, unless the objects created in the subclasses are also Player objects. A subclass is used to define a more specific type of whatever object the parent class creates. For example, you might find the following parent to child links: Object >> Actor >> Animal >> Feline >> HouseCat. Note how each child is a type of its parent class. By having all subclasses extends the Player class, all objects created from those subclasses are considered Player objects. But, I would think you have one player (probably); and, if you had more, the only extensions from the Player class should be, for example, PlayerA, PlayerB, etc.
luGGas luGGas

2022/7/7

#
Oh, right. I forgot about that. Thanks
You need to login to post a reply.