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

2018/11/17

How to controll the time

wueschn wueschn

2018/11/17

#
Dear Experts I have a problem with the constructor of an actor. I want every actor not to appear from beginning on without delay. It would be perfect, if it is appearing for the first time after 10 seconds. I tried this, but it does not work, what ever delay i put into:
public class Klingonen extends Actor
{

    public Klingonen()
    {
       
        int zahl = Greenfoot.getRandomNumber(2) + 1;
        this.setImage("k" + zahl + "." + "png");
        Greenfoot.delay(100000);
        this.getImage().setTransparency(0);
        this.setRotation(Greenfoot.getRandomNumber(65) - 5);
        
        

    }
public void act() 
    {
        if(Greenfoot.getRandomNumber(1000) < 2)
        {
            if(this.getImage().getTransparency() == 0)
            {
             
                this.getImage().setTransparency(110);
               
            }
            else
            {
                this.getImage().setTransparency(0);
            }

        }
    }    
Every solution is helpful for me. Thanks a lot! wueschn
danpost danpost

2018/11/17

#
Remove line 9 from the Klingonen class. The Greenfoot class delay method will pause everything, not just spawning of actors. Use an int field in your subclass of World to count act cycles and presume 60 acts to equal one second of time. When the counter reaches 600 (60 acts times 10 secconds) spawn a Klingonen object and reset the counter to zero (use an act method in your extension of World.
wueschn wueschn

2018/11/18

#
Thanks a lot, it works!!
You need to login to post a reply.