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

2021/5/28

Passing More Then one Reference to One Actor

yakub yakub

2021/5/28

#
Hello, I am trying to create a game that has 3 counters: health, score and fuel. I am trying to pass a reference to all those to my spaceship. I have managed to do that for fuel, but I don't know how to reference the rest. Here is my code:
private void prepare()
    {

        FuelCounter fuelcounter = new FuelCounter();
        addObject(fuelcounter,41,34, false); //Adds the fuel counter and makes it non-scrollable object.
        
        HealthCounter healthcounter = new HealthCounter();
        addObject(healthcounter,83,34, false);

        setMainActor(new Spaceship(fuelcounter), 0, 0);
        mainActor.setLocation(300,3500);
In the
setMainActor(new Spaceship(fuelcounter), 0, 0);
mainActor.setLocation(300,3500);
section I was thinking of putting
setMainActor(new Spaceship(fuelcounter, healthcounter), 0, 0);
mainActor.setLocation(300,3500);
but that doesn't work. What should I do?
danpost danpost

2021/5/28

#
Adjust the constructor to make it work -- public Spaceship(FuelCounter fuelcounter, HealthCounter healthcounter)
yakub yakub

2021/5/29

#
danpost wrote...
Adjust the constructor to make it work -- public Spaceship(FuelCounter fuelcounter, HealthCounter healthcounter)
Thank you, it worked.
You need to login to post a reply.