Starfield

J

Jan2

Guest
How can I make a randomly generated starfield, where stars are placed randomly? I expect stars not to be instances, because this will be a very bad solution. They should be DRAWN like this!

rgbcolor = make_colour_rgb(255,255,255);
draw_set_color(rgbcolor);
for(i=0;i<50;++i)
{
x_pos = random_range(0,room_width);
y_pos = random_range(0,room_height);
draw_circle(x_pos,y_pos,3,false);
}
 
Last edited by a moderator:

jo-thijs

Member
If no other random functions have to be performed while the stars exist,
you could use randomize in the create event, store the current seed
and restore that seed every time before drawing.

Otherwise, you could calculate every x_pos and _ypos in the create event and store the coordinates in an array
and loop through that array in the draw event.
 
M

maartenvt

Guest
If you don't need to interact with the stars later you could draw them on a surface.
 

jo-thijs

Member
The surface idea has its advantages and disadvantages.
It will allow faster drawing, but you will need to take into account the fact that surfaces can be deleted whenever (e.g. when minimizing).
They also take up way more memory.
 
I

icuurd12b42

Guest
draw a sprite not a circle
call random_set_seed(1000); //arbitrary value
before the loop

and
randomize() after the loop.

this should make the stars draw at the same position each draw
 
Last edited by a moderator:
Top