Re: Display problem

BlitzMax Forums/BlitzMax Beginners Area/Re: Display problem

Joe90bigrat90(Posted 2011) [#1]
ok ive got a slight problem here. And i'm sure im just doing something silly.

graphics 1920,1080

'all my variables and arrays go here

'load all of my animimages here

setclscolor 204,204,204 'set screen color to grey
setblend(shadeblend)
delay(30)

while not keydown(KEY_ESCAPE)
      cls 'clear the screen set by setclscolor 'grey

'check for key presses here and draw images to the screen

flip

wend

endgraphics
end


Ok heres my problem. I want to insert this code into my program to draw random blocks on the screen. The code is this:


For a=0 To numberofbuildings-1
	buildingx[a]=Rnd(1870) 'store random number in x upto 1870	
	buildingy[a]=Rnd(970) 'store a random number in y upto 970
	DrawImage (building,buildingx[a],buildingy[a],0)
Next


But everytime i put it inside my while loop it just keeps flashing loads of random blocks on the screen. I guess because it is inside a while loop. If i put it outside of the while loop before the while you wont see anything because of the cls inside the while loop. If i remove the cls in the while loop then my sprites wont display.

so can anyone tell me how i can put this short code into my while loop so that the blocks stay on the screen and my sprites work also.

I just need to know where to put it. Im in a catch 22 situation.

Inside the loop it keeps repeating itself and outside the loop it never gets drawn.

Arhhhhhhhhhhhhhhhhhhhhhh Help me please
thankyou


Pengwin(Posted 2011) [#2]
This code:

For a=0 To numberofbuildings-1
	buildingx[a]=Rnd(1870) 'store random number in x upto 1870	
	buildingy[a]=Rnd(970) 'store a random number in y upto 970
	DrawImage (building,buildingx[a],buildingy[a],0)
Next


when placed inside the loop will draw the buildings at random coordinates each iteration of the loop.

If you want to have random buildings in your game, you will need to set the coordinates outside of the loop and put the drawing in the loop.

e.g.

graphics 1920,1080

'all my variables and arrays go here

'load all of my animimages here

setclscolor 204,204,204 'set screen color to grey
setblend(shadeblend)
delay(30)

'Initialise the building positions  ************************************
For a=0 To numberofbuildings-1
	buildingx[a]=Rnd(1870) 'store random number in x upto 1870	
	buildingy[a]=Rnd(970) 'store a random number in y upto 970
Next

while not keydown(KEY_ESCAPE)
      cls 'clear the screen set by setclscolor 'grey

'Draw the buildings  ************************************
      For a=0 To numberofbuildings-1
	     DrawImage (building,buildingx[a],buildingy[a],0)
      Next

      flip

wend

endgraphics
end



H&K(Posted 2011) [#3]
Re seed random each loop
Seed=MilliSecs()
Outside loop
seedrnd Seed
Inside loop

This is probably (well almost certainly) NOT the was to do it, just a "thinking" point so you can see better what the comp is doing.


Joe90bigrat90(Posted 2011) [#4]
Thankyou so much. It works a treat.
Many thanks for your help.
Cheers
Kind Regards
Joe