I have a title text string that moves across the screen from left to right (starting off the screen). I wrote code for it to move right and then stop in the middle of the world but I now want to add code that makes it move right all the way to the edge of the world (getX()==460) and then move left until it reaches the middle of the world (230,230). I tried to use booleans but can't get it to work. Thanks for any help
**The problem seems to be with the booleans because it gets to getX()==460 and then moves left to getX()==459. The problem is the boolean only changes when the object is at getX()==460 and then returns to what it was before.
import greenfoot.*;
import java.awt.Color;
import java.awt.Font;
/**
* Write a description of class Title here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Title extends Actor
{
private float fontSize;
private GreenfootImage img;
public boolean move, move2;
public Title()
{
fontSize = 20.0f;
img = new GreenfootImage(230, 100);
img.setFont(new Font("Courier New", Font.PLAIN, 40));
img.setColor(Color.WHITE);
img.drawString("Breakout", 25, 40);
setImage(img);
move = false;
move2 = true;
}
/**
*
*/
public void act()
{
if (getX()<460&&move==false)
{
moveRight();
}
if(getX()<460&&move==true)
{
moveLeft();
}
}
public void moveRight()
{
if(move2==true)
{
move(2);
}
}
public void moveLeft()
{
if(move2==false)
{
move(-2);
}
}
}
