I have to create Hint type text, along with background for it. There will be almost the same text for both players, but it will appear when needed and dissapear when task is done, but i have tried something which is not working. Can someone help me?
private void DisplayText()
{
getWorld().addObject(new HoldCtoCut(100,100, Player), 100,100);
// getWorld().addObject(new GoToVent(), 100,100);
getWorld().addObject(new AfterCuttingPressE(100,100),100,100);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class HoldCtoCut here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class HoldCtoCut extends TextBox
{
String text = " Hold E to start cutting the vents ";
public void HoldCtoCut( int x,int y, int Player)
{
if( Player == 1 )
{
getWorld().addObject(new Box( x, y), 100,500);
}
else
{
getWorld().addObject(new Box( x, y), 800,500);
}
GreenfootImage HoldCtoCut = new GreenfootImage(100,30);
HoldCtoCut.drawString(text, 2, 20);
setImage(HoldCtoCut);
}
public void act()
{
// Add your action code here.
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Box here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Box extends Jobs
{
public void Box( int x,int y)
{
GreenfootImage image = new GreenfootImage(x, y);
image.setColor(Color.RED);
image.fill();
setImage(image);
}
public void act()
{
// Add your action code here.
}
}
public HoldCtoCut()
public void DisplayText()
{
addObject(new Box(100, 100), Player*700-600, 100);
addObject(new HoldCtoCut(), 100, 100);
addObject(new AfterCuttingPressE(100, 100), 100, 100);
}public void HoldCtoCut()
{
Background();
Text();
}
private void Text()
{
// here i put the text
}
private void Background()
{
// here i put the background for text
}import greenfoot.*;
public class Hint extends Actor
{
public Hint(String text)
{
setText(text);
}
public void setText(String text)
{
GreenfootImage textImg = new GreenfootImage(text, 24, Color.BLACK, new Color(0, 0, 0, 0));
GreenfootImage img = new GreenfootImage(100, 100);
img.setColor(Color.RED);
img.fill();
img.drawImage(textImg, 50-textImg.getWidth()/2, 50-textImg.getHeight()/2);
setImage(img);
}
}private Hint hint = new Hint{" ");String text = "Hold E to\nstart cutting\nthe vents"; hint.setText(text); addObject(hint, Player*700-600, 100);
Cut cutActor = new Cut();
Cut cut = (Cut) getWorld().getObjects(Cut.class).get(0);