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

2017/1/27

Is There A Way To Get Characters To Speak?

BrantnerGrace BrantnerGrace

2017/1/27

#
Hey I really need help, I am trying to create an adventure game and I don't know how to get characters to speak or at least add a bar at the bottom that text can be in and your press a button to continue. I am trying to make an RPG styled game. Any help would be appreciated!
danpost danpost

2017/1/27

#
What have you tried? You probably need to start with an Actor subclass to display a clip of the dialog. It should probably not allow any other actions to occur while waiting for the press of the key (notice the italicized word). See what you can do. If you have difficulties on specifics, report back your issues here.
BrantnerGrace BrantnerGrace

2017/1/28

#
I have tried putting an image up, but I would like to have a proper dialogue box that people can interact with if you know what I mean. I have no idea how to do it, we are doing a game contest in my lesson and my teacher doesn't know how to do it you see...
danpost danpost

2017/1/29

#
BrantnerGrace wrote...
I have tried putting an image up, but I would like to have a proper dialogue box that people can interact with if you know what I mean. I have no idea how to do it, we are doing a game contest in my lesson and my teacher doesn't know how to do it you see...
What kind of interaction? Please give an example for clarity.
BrantnerGrace BrantnerGrace

2017/2/2

#
Text dialogue boxes...
Super_Hippo Super_Hippo

2017/2/2

#
You can add an Actor which uses the text as its image. If you want some text choices in some kind of dialogue and the one which is clicked is used for the character, add an Actor for each text choice and when one is clicked, use that one, remove all text and replace it with the next texts.
BrantnerGrace BrantnerGrace

2017/2/3

#
Super_Hippo wrote...
You can add an Actor which uses the text as its image. If you want some text choices in some kind of dialogue and the one which is clicked is used for the character, add an Actor for each text choice and when one is clicked, use that one, remove all text and replace it with the next texts.
Okay thank you. Would it be possible to make it appear for a certain period of time?
Super_Hippo Super_Hippo

2017/2/3

#
Then the easiest way would probably to add a separate class for it. It could look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Text extends Actor
{
    private int duration = -1;
     
    public Text(String text, int size, int time)
    {
        setImage(new GreenfootImage(text, size, null, null)) //black on transparent, you can also use other colors/pass them to the constructor
        duration = time;
    }
 
    public Text(String text, int size)
    {
        this(text, size, -1);
    }
     
    public void act()
    {
        if (time > 0)
        {
            time--;
            if (time == 0) getWorld().removeObject(this);
        }
    }
}
Then you can add a text object like this:
1
addObject(new Text("Hello", 20, 300), 200, 200);
You need to login to post a reply.