import greenfoot.*; import java.awt.Color; public class Dialog extends Actor { private GreenfootImage baseImage, textImg; private int textspeed; private GreenfootImage scroll = new GreenfootImage("scroll.png"); private String text[]; public Dialog(String text[], int size) { scroll.scale(544,64); baseImage = new GreenfootImage(544,64); baseImage.drawImage(scroll,0,0); setText(text, size); updateImage(); } public void setText(String text[], int size) { int fontsize = size; for(int i = 0; i<text.length;i++){ GreenfootImage stringpic = new GreenfootImage(text[i], fontsize, greenfoot.Color.BLACK, null); Font textFont = new Font ("Calibri", fontsize); stringpic.setFont(textFont); textImg = new GreenfootImage(stringpic.getWidth(), 50); textImg.drawImage(stringpic, 0, 40-stringpic.getHeight()); textspeed = baseImage.getWidth(); while(!Greenfoot.isKeyDown("space")){ Greenfoot.delay(1); } } } private void updateImage() { GreenfootImage image = new GreenfootImage(baseImage); image.drawImage(textImg, textspeed, 0); setImage(image); } public void act() { textspeed--; if (textspeed ==-textImg.getWidth()) textspeed = baseImage.getWidth(); updateImage(); } }