Hello there,
I’m currently working on a 2d sandbox survival type game and I’m trying to implement a system that changes the player sprite based on the name you input. I’ve tried messing around with many different methods to do this, but none of them seem to be working. The current;y code I have for getting the string input is this:
public static String getUserName() {
if (username.getText() != null) {
return Main.player.username = username.getText();
}
return "";
}
}
And here is the part that displays the name above the player and displays the sprite:
if (username != null) {
if (Main.dir == movementSpeed) {
g.drawImage(image);
} else {
g.drawImage(image);
}
g.setColor(Color.WHITE);
g.setFont(Main.size8);
g.drawString(username, (int)x - (int)Main.sX - username.length() * 3 / 2, (int)y - (int)Main.sY);
} else {
System.out.println("null");
}
Thank you for any possible feedback and help
*Should be noted that I am not using any libraries