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

2019/4/7

Making the using write something on screen

Scarley Scarley

2019/4/7

#
Im currently doing a project for my university, i already made a playable game but i also want the user to write, kinda like making the user call the correctly functions to make my character move, is there anyway to do it?
Super_Hippo Super_Hippo

2019/4/8

#
You can have an Actor and on its image you print a String. Then you can adjust the String whenever needed and update the image.
private String input = "";

public ClassName()
{
    updateImage();
}

public void act()
{
    String key = Greenfoot.getKey();
    if (key != null)
    {
        //check for special keys like space, backspace, escape, ...
        if ("space".equals(key)) key = " ";
        //…
        input = input + key;
        updateImage();
    }
}

private void updateImage()
{
    //create an image, draw the String input on it
}
You need to login to post a reply.