This site requires JavaScript, please enable it in your browser!
Greenfoot back
Back to discussions
matthijs124
matthijs124 wrote ...

2017/11/10

Need help displaying dialogue

matthijs124 matthijs124

2017/11/10

#
I want to display dialogue in my game. Until now, I have not been able to create the right code to do this. I have looked up some examples on the internet of how I want it to be like: (I do not know these games, these are just for example) I think it is too much work to constantly use another image that was created with text beforehand, but I want to use the 'text box' template and just add text in Greenfoot. But how?
danpost danpost

2017/11/10

#
I would use an array for the dialogue content and have a method in the world to create a dialogue object. In the method, create a text GreenfootImage. Then create a blank GreenfootImage that is a bit larger so you can draw a frame on it as well as drawing the text image on it. You could even have the method receive an icon image to draw on the image as well. Or, just pass an index value to the array and let the method get the information needed, which can then include color values for text, background and frame, image file name and scaling values, etc. Finally, create an Actor object and set the framed image to it and add it to the world.
matthijs124 matthijs124

2017/11/13

#
I now run into a problem. When try to add the object "Text", I use addObject(). I have to fill in the X and the Y. When I draw the string, I use : GreenfootImage t = new greenfoot.GreenfootImage(), where I have to fill in 2 coordinates again. Also, I'm having some problems with removing the text after placing it...
danpost danpost

2017/11/13

#
matthijs124 wrote...
I now run into a problem. When try to add the object "Text", I use addObject(). I have to fill in the X and the Y. When I draw the string, I use : GreenfootImage t = new greenfoot.GreenfootImage(), where I have to fill in 2 coordinates again. Also, I'm having some problems with removing the text after placing it...
1) where are you drawing the string? 2) why are you drawing a string? 3) which GreenfootImage constructor are you using? 4) why isn't your problem code posted?
matthijs124 matthijs124

2017/11/14

#
I got it working. I used a single line of code in the constructor of a Text class, with a parameter for the string I want to draw.
You need to login to post a reply.