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

2018/1/26

Draw lines bg with pic

RevoltecX7 RevoltecX7

2018/1/26

#
Hi, I want ask you - how to redraw some lines? My lines is created by "for", which it repeat randomly on map 50 times. I want make "raining" in game. Could you help please?
Super_Hippo Super_Hippo

2018/1/26

#
Show what you have, what happens and what is different to what should happen.
RevoltecX7 RevoltecX7

2018/1/26

#
    private int thickness = 3;
    private int rndmX, rndmY;
    public Dead()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        showText("You are dead :(", 300, 240);
        
    }
    
    private void thicknessLine(int x, int y){
        for(int j=0;j<thickness;j++){
            this.getBackground().drawLine(x+j,y+j,x+100+j,y+200+j);
        }
    }
    
    public void act(){
        for(int i = 0; i < 50; i++){
            rndmX = Greenfoot.getRandomNumber(600);
            rndmY = Greenfoot.getRandomNumber(400);
            thicknessLine(rndmX, rndmY);
        }
        Greenfoot.delay(1);
    }
I don't know why u need this, when i told - what i really need. But maybe I told it bad.... so here is what i want to do: I need -> after draw a line, remove the line. I have background - so i can't use "white" or else color for re-draw it.
Vercility Vercility

2018/1/27

#
Redraw and remove are two different things Redraw means draw it again Remove means delete AFAIK there's no Way to do that except for saving the background before drawing and then reloading it
RevoltecX7 RevoltecX7

2018/1/27

#
And what I write? ...
RevoltecX7 wrote...
i can't use "white" or else color for re-draw it.
I have one idea for it... when I will create rain, after 1 sec I will screate image of bg (for full screen), and repeat(rain, 1s, image, rain, 1s, bg..) It's good idea?
danpost danpost

2018/1/27

#
Keep main background image in a field. Each act, you will need to create a new image using the main image and draw the rain on it. Example:
// fields
private GreenfootImage bg;
private GreenfootImage rain = new GreenfootImage("rain.png"); // cannot be a jpeg image (needs transparency)
int rainOffset;

// in constructor
bg = getBackground();

// in act
GreenfootImage bgNew = new GreenfootImage(bg);
rainOffset = (rainOff+4)%getHeight();
bgNew.drawImage(rain, 0, rainOffset);
bgNew.drawImage(rain, 0, rainOffset-getHeight();
You need to login to post a reply.