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

2020/3/2

Boss with healthbar

1
2
3
Yoshi21137 Yoshi21137

2020/3/2

#
I am trying to make a boss with a healthbar and it works but I want to make it so that the healthbar stays above the boss, even if the boss turns. Does anyone know how to do that?
footpickle footpickle

2020/3/2

#
have you tried using setLocation()?
Yoshi21137 Yoshi21137

2020/3/2

#
yes but I don't know how to access the boss's location from the healthbar
footpickle footpickle

2020/3/2

#
I think in the healthbar class you need to add Boss boss = new Boss() (or whatever the boss is called) and I think the setLocation is getWorld().setLocation but I dont really know
danpost danpost

2020/3/2

#
footpickle wrote...
I think in the healthbar class you need to add Boss boss = new Boss() (or whatever the boss is called)
That will not work. That will create a second Boss object and will it will not tell you anything about where the one already in the world is at.
and I think the setLocation is getWorld().setLocation but I dont really know
You cannot use an Actor class method (setLocation) on a World object (from getWorld). The Boss object should keep a reference to its health bar and it (the boss) should re-position the bar anytime it (the boss) moves.
Yoshi21137 Yoshi21137

2020/3/2

#
How would I do that. How do I set the location of the health bar from the boss
footpickle footpickle

2020/3/3

#
Oh. Ok. I guess I'm dumb. What WOULD be the solution, then?
danpost danpost

2020/3/3

#
Yoshi21137 wrote...
How would I do that. How do I set the location of the health bar from the boss
If your health bar had a field:
1
private Boss boss;
and if the boss that is in the world was assigned to that field, then you could use something like:
1
boss.setLocation(getX(), getY()-25);
Hold on -- editing massively here.
footpickle footpickle

2020/3/3

#
Would that be in the boss class, or in a separate helthbar class?
danpost danpost

2020/3/3

#
footpickle wrote...
Would that be in the boss class, or in a separate helthbar class?
I said hold on. Now I have to type everything out again -- but correctly.
danpost danpost

2020/3/3

#
Yoshi21137 wrote...
How would I do that. How do I set the location of the health bar from the boss
If your boss had a field:
1
private Healthbar healthbar;
and if the health bar that is added into the world was assigned to that field, then you could use something like:
1
healthbar.setLocation(getX(), getY()-25);
footpickle footpickle

2020/3/3

#
Oh. sorry :/
danpost danpost

2020/3/3

#
footpickle wrote...
Would that be in the boss class, or in a separate helthbar class?
danpost wrote...
If your boss had a field
My third word indicates what class.
footpickle footpickle

2020/3/3

#
Ok, but what is a field?
danpost danpost

2020/3/3

#
footpickle wrote...
Ok, but what is a field?
If you have to ask that, you better start from the beginning: Trail: Learning the Java language
There are more replies on the next page.
1
2
3