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

2017/3/21

Add object isn't working!

Grace20102 Grace20102

2017/3/21

#
    public void act() 
    {
        timer++;
        if (timer == 40) getWorld().removeObject(this);
        setImage(new GreenfootImage("Message2.png"));
        if (timer == 80) getWorld().addObject(this);
    }    
This is what I have, I am trying to add in the message again after I took it out. I took this section of code from the message actor. The addObject bit isn't working.
Super_Hippo Super_Hippo

2017/3/21

#
The act method is only executed when the actor is in the world. So an actor can't add itself from its act method. Maybe giving the object an invisible image is working?
public void act()
{
    timer++;
    switch (timer)
    {
        case 40: setImage(new GreenfootImage(0,0)); break; //set invisible image
        case 80: setImage("Message2.png")); break;
    }
}
Grace20102 Grace20102

2017/3/21

#
Thank you so much for your help! I managed to resolve the problem with help from your code! Here is what I did!
    private int timer;
    public void act() 
    {
        timer++;
        if (timer == 100) setImage(new GreenfootImage("Transparent.png"));
        if (timer == 250)setImage(new GreenfootImage("Message2.png")); 
    }
All I did was make a transparent image and switched it too that.
woodmoor03 woodmoor03

2017/3/21

#
what are you trying to get working
Grace20102 Grace20102

2017/3/21

#
woodmoor03 wrote...
what are you trying to get working
A zombie game I am making :D
You need to login to post a reply.