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

2021/1/14

Showing text above a moving actor

1
2
3
4
Roshan123 Roshan123

2021/1/14

#
How to show text above a moving actor Conditions:- 1. Without making another class to show text 2. The text should move above the actor
danpost danpost

2021/1/14

#
Roshan123 wrote...
How to show text above a moving actor Conditions:- 1. Without making another class to show text 2. The text should move above the actor
Will the text be constant or should it be changeable? What text is to be displayed? Give example(s).
Roshan123 Roshan123

2021/1/14

#
I want it to move for every fps with the tank
Roshan123 Roshan123

2021/1/14

#
Example I only want to write name above it
Roshan123 Roshan123

2021/1/14

#
I have a tank obj And i want the text to move with the tank and the text is a constant name Show text(Michael Kolling)
danpost danpost

2021/1/14

#
Maybe you can use:
getWorld().showText(name, getX(), getY()-45);
at end of constructor and at end of act method, with:
getWorld().showText(null, getX(), getY()-45);
at the beginning of the act method.
Roshan123 Roshan123

2021/1/14

#
Will the text move along with the tank???
Roshan123 Roshan123

2021/1/14

#
Initially i thought about it but afterwards i thought that it will simply draw it on the background of the world. Ok... Whatever it may be, 1st of all i should try!
danpost danpost

2021/1/14

#
Roshan123 wrote...
Will the text move along with the tank???
If you put those line in where I said ... yes.
Roshan123 Roshan123

2021/1/14

#
danpost wrote...
Roshan123 wrote...
Will the text move along with the tank???
If you put those line in where I said ... yes.
Ok!!)
Roshan123 Roshan123

2021/1/14

#
danpost wrote...
Maybe you can use:
getWorld().showText(name, getX(), getY()-45);
at end of constructor and at end of act method, with:
getWorld().showText(null, getX(), getY()-45);
at the beginning of the act method.
Error- An attempt was used to use actor location. Either it has been removed or i don't remember
danpost danpost

2021/1/14

#
Roshan123 wrote...
Error- An attempt was used to use actor location. Either it has been removed or i don't remember
Sorry. Remove line from end of constructor. Add the following method:
protected void addedToWorld(World world)
{
    world.showText(name, getX(), getY()-45);
}
Roshan123 Roshan123

2021/1/15

#
//constructor 
protected void addedToWorld(World world)
{
    world.showText(name, getX(), getY()-45);
}
public void act
{
getWorld().showText(null, getX(), getY()-45);
//Rest of the code
}
Its still not adding text
danpost danpost

2021/1/15

#
Roshan123 wrote...
<< Code Omitted >> Not adding to the world
You should have line 4 AGAIN before line 10.
Roshan123 Roshan123

2021/1/15

#
//Constructor
protected void addedToWorld(World world)
{
    world.showText(name, getX(), getY()-45);
}
public void act
{
getWorld().showText(null, getX(), getY()-45);
//Rest of the code
getWorld().showText(name, getX(), getY()-45);
}
Do u mean something like this???
There are more replies on the next page.
1
2
3
4