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

2014/1/7

Severe bug which makes no sense.

nosyarg nosyarg

2014/1/7

#
if (Greenfoot.mousePressed(this) && counter>9 )
        {
            System.out.println("fire");
            img.setTransparency(125);
            img.setColor(Color.red);
            mouseinfo = Greenfoot.getMouseInfo();
            img.clear();
            if (mouseinfo != null && img != null)
            {
                x = mouseinfo.getX();
                y = mouseinfo.getY();
                System.out.println(x + "," + y);
                img.drawLine(Human.getX(),Human.getY(),x,y);
            }
            this.setBackground(img);
            counter = 0;
            
        }
This is a snippet of my code for a project which I am doing. It should set the background to a white image with a red line between a sprite and the mouse location upon each click. It has some extra code in from where I have been trying to debug it but there is a horrible and inexplicable bug which happens. The sprites moving around on screen (currently all the default foot) leave a trail of their former positions and the buttons on the greenfoot ui appear on the screen, does anyone have any idea what is happening?
erdelf erdelf

2014/1/7

#
Well, is the trail only existent if u are clicking`?
danpost danpost

2014/1/7

#
Line 7 is causing the problem, making the background image transparent, which results in the strange behavior with the buttons of the greenfoot ui. Instead of 'clear', set color to white and 'fill', then set color to red to draw the line.
nosyarg nosyarg

2014/1/7

#
Thank you! that made it work perfectly, do you know why the greenfoot buttons would do that by the way? It doesnt seem like a functionality which would be useful for anything...
danpost danpost

2014/1/7

#
nosyarg wrote...
Thank you! that made it work perfectly, do you know why the greenfoot buttons would do that by the way? It doesnt seem like a functionality which would be useful for anything...
I could not say. However, there should be no visibility through the background image of your world and therefore makes sense that that image be opaque (not at all transparent).
You need to login to post a reply.