How do I get a random number to stay fixed with slick? -


i'm beginner in java slick tools. want make game has different coloured cubes randomly placed within area of window.

i use 2 for-loops , call random number in render. cubes placed want, problems flicker in colours. guess has how call random number , gets updated fps?!

please me!!

    public void render(gamecontainer gc, statebasedgame sdg, graphics g) throws slickexception {     //set background      image background = (new image("res/background.png")).getscaledcopy(800, 500);        g.drawimage(background, 0, 0);      //set gamescape     blue = (new image("res/blue.png")).getscaledcopy(20,20);     green = (new image("res/green.png")).getscaledcopy(20,20);     red = (new image("res/red.png")).getscaledcopy(20,20);     int xvalue = 300;     int yvalue = 400;       (int = 1; < 20; a++) {          (int = 1; < 10; i++) {               r = rand.nextint(3);             if(r==0){g.drawimage(blue,xvalue,yvalue);}              else if(r==1){g.drawimage(red, xvalue, yvalue);}              else{g.drawimage(green, xvalue, yvalue);}              xvalue = xvalue+20;         }         yvalue = yvalue - 20;         xvalue = xvalue -180;     }   }    

your problem generate new random number each time redraw scene.

to resolve this, may have create array in store generated color of each cube. , each time redraw images, read each color value in array.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -