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

2016/3/19

Crashed background ?

fejfo fejfo

2016/3/19

#
I was trying to generate the background of my world in code (a background made of dirt with some stones) and I got some crashed pixels these crashed pixels are white at the start and then just keep the color of the last actor at that position Does anyone know what causes this ? (alpha data ?) EDIT : I added an b.fill() after the b.setColor and the crashed pixels disappeared so I guess it was alpha but I still don't really understand why this bug accours doesn't Greenfoot check for this ? if not I found you a bug (I'm using an older version so it may be fixed already) I don't really think you need the code but I will post a part of it anyway
protected void generateBackground() {
        GreenfootImage b = new GreenfootImage(getWidth()/7,getHeight()/7);
        //make the ground brown
        b.setColor(new Color(57,37,23));
        //randomise the ground
        int groundPatches = Greenfoot.getRandomNumber(b.getWidth()*b.getHeight()/21);
        for(int i = 0; i < groundPatches; i++) {
            addPatch(b, 21, new Color(57,37,23), 7, 3, 5);
        }
        //add random stones
        //Color c = new Color(70+rNum(-7,7),70+rNum(-7,7),70+rNum(-7,7));
        int stones = Greenfoot.getRandomNumber(b.getWidth()*b.getHeight()/(21*5));
        for(int i = 0; i < stones; i++) {
            addPatch(b, 21, new Color(70,70,70), 7, 7, 7);
        }

        b.scale(getWidth(),getHeight());
        setBackground(b);
    }
danpost danpost

2016/3/19

#
fejfo wrote...
I was trying to generate the background of my world in code (a background made of dirt with some stones) and I got some crashed pixels
That is usually what happens when you add transparency to your world background image. Fill the background image 'b' with Color.WHITE after creating it.
You need to login to post a reply.