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

2017/3/30

Problem with image appearing twice

HardToFindAName HardToFindAName

2017/3/30

#
Hello everyone! So I have a problem which I can't seem to be able to sort out by myself. You see, I made a game some time ago, and I want to fix it now. Here's the thing. There is a timer (calendar actually) and when day 8 arrives I want the game to display a banner with Election Day and then that banner to disappear. I've also added a skip button, so when pressed the day reaches 8 and the election comes so the banner should appear. This is the piece of code. I created an object named ElecDay with that banner as the image, and here's what's happening:
skip skip=((Harta)getWorld()).getSkip();
        if (Greenfoot.mouseClicked(skip))
        {
            i=8;
            setImage(new GreenfootImage(i+" NOV "+ "2016",18, Color.BLACK, Color.WHITE));
            j=3;
            Greenfoot.delay(240);
            elecDay elecDay=((Harta)getWorld()).getelecDay();
            getWorld().addObject(elecDay,600,150);
            Greenfoot.delay(20);
            getWorld().removeObject(elecDay);
            
            safetycontrol=false;
        }
and here is the code in the world editor:
private elecDay elecDay=new elecDay();
private skip skip=new skip();
.
.
.
public elecDay getelecDay()
{
    return elecDay;
}
public skip getSkip()
{
    return skip;
}
Now, what's happening: the game seems to freeze according to the delay, but the static image doesn't change even though I wrote the command before. It freezes, then the static image changes and simultaneously the banner appears, then immediately disappears, then the banner appears, freezes according to that second delay and then disappears. What should I do to make it work? Thank you in advance! Paul
HardToFindAName HardToFindAName

2017/3/30

#
Solved it anyway. Basically, I did the following:
if (the skip button is pressed)
{
    add object to the world;
}
//in the object's editor
if (object was added to the world (I said getWorld()!=null, didn't know it was possible, lol)
{
   remove object;
}
Thank you anyway! :)
danpost danpost

2017/3/30

#
Out of curiosity, what code do you have in the skip class.
You need to login to post a reply.