I wonder if theres a Way to create a Field, were people can type a name they want (must have a lenght maximum), which is shown directly over the User, everytime he plays the game
String name = "User";
public void started()
{
for (int i=0; i<3; i++)
{
String nm = Greenfoot.ask("Enter name (no more than 10 characcters long)");
if (nm == null || "".equals(nm) || nm.length() > 10) continue;
name = nm;
}
}String name;
Actor namePlate;
public Player(String nm)
{
name = nm;
}
protected void addedToWorld(World world)
{
namePlate = new NamePlate();
namePlate.setPosition();
}
public void act()
{
// put at end and before any 'return;' statements
namePlate.setPosition();
}
// still in Player class
private class NamePlate extends Actor
{
public NamePlate()
{
GreenfootImage img = new GreenfootImage(name, 17, Color.BLACK, Color.CYAN);
setImage(img);
}
public void setPosition()
{
if (Player.this.getWorld() == null)
{
if (getWorld() != null) getWorld().removeObject(this);
return;
}
if (getWorld() == null) Player.this.getWorld().addObject(this, 0, 0);
setLocation(Player.this.getX(), Player.this.getY()-Player.this.getImage().getHeight()/2-10);
}
}