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

2014/9/25

removing copies

Kirito101 Kirito101

2014/9/25

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class wheel here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class wheel extends Actor
{
    boolean run=true;int time=100;
    /**
     * Act - do whatever the wheel wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        World world;
       world=getWorld();
        int locX = ((PlayerCar) getWorld().getObjects(PlayerCar.class).get(0)).getX();
        int locY = ((PlayerCar) getWorld().getObjects(PlayerCar.class).get(0)).getY();
        // Add your action code here.
        if(run==true){
        turnTowards(locX,locY);run=false;}
        if(time<0){
        world.removeObject(this);time=100;}
    }    
}
how do I make the lines go under the car and get removed after a period of time?Thanks ahead of time.
Super_Hippo Super_Hippo

2014/9/25

#
Maybe you should add a line like this in your act method:
time--;
By the way, the following way is more efficient I think:
private int time = 100;

protected void addedToWorld(World w)
{
    turnTowards(getWorld().getObjects(PlayerCar.class).get(0)).getX(),getWorld().getObjects(PlayerCar.class).get(0)).getY());
}

public void act()
{
    time--;
    if (time<0) getWorld().remove(this);
}
You need to login to post a reply.