Good evening,
I have a problem with a certain code. I am trying to say that if the elapsedTime is Higher then 3000 it has to delete the object grindzak. But it never comes in the code that says : remove.Object (this);. I tried to do a system.out.print of the elapsedTime but it never gets higher then 150. I think that has something to do with the act method because an act is happenning every 143Milliseconds, so it never gets higher then 150. I hope you can help me out what i want it to do is the delete the object grindzak after 3 seconds. the code is :
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class grindzak here. * * @author (your name) * @version (a version number or a date) */ public class grindzak extends Burger { /** * Act - do whatever the grindzak wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ private long initialTime = System.currentTimeMillis(); public void act() { Actor checkWater = getOneIntersectingObject(Watervloed.class); long currentTime = System.currentTimeMillis(); long elapsedTime = currentTime - initialTime; if(checkWater != null) { getWorld().removeObject(checkWater); if(elapsedTime > 1000) { initialTime = currentTime; getWorld().removeObject(this); } } } }