31Nf4ChZ4H73N
Member
I followed this youtube tutorial to create Voronoi Diagrams using surfaces in game maker 2. so far it works but my colors are not really random but they are all a dark redish. I could not figure out where this happens, though.
oMapGeneration
oSeed
oBiomeCreate
As I understood the in the oMapGeneration the seeds are getting their positions and they are getting their colors which are randomized.
Then in oBiomeCreate it just loops trough every pixel and is looking for the closest seed to that pixel then it draws sets the surface on that pixel to the color of the closes seed
I really do not understand why picks those colors everytime:
oMapGeneration
GML:
/// Create Event
randomize();
// Create surface
global.width = room_width;
global.height = room_height;
global.biome_surface = surface_create(global.width,global.height);
// Seeds to create
seeds = 8;
// Create seed
repeat (seeds) {
var xx = irandom(global.width);
var yy = irandom(global.height);
with instance_create_layer(xx,yy,layer,oSeed) {
var red = irandom(255);
var green = irandom(255);
var blue = irandom(255);
biome_color = make_color_rgb(red,green,blue);
}
}
// Create object that draws
instance_create_layer(0,0,layer,oBiomeCreate);
GML:
/// draw event
draw_surface_ext(global.biome_surface,0,0,1,1,0,c_white,1);
Code:
//Create Event
biome_color = c_white;
biome_name = "";
depth = -1000;
GML:
///Create Event
for (var xx = 0; xx < global.width; xx++) {
for (var yy = 0; yy < global.height; yy++) {
x = xx;
y = yy;
// Get nearest seed
var seed = instance_nearest(x,y,oSeed);
surface_set_target(global.biome_surface);
// Add sprite to surface
draw_sprite_ext(sprite_index,0,x,y,1,1,image_angle,seed.biome_color,1);
surface_reset_target();
}
}
instance_destroy();
Then in oBiomeCreate it just loops trough every pixel and is looking for the closest seed to that pixel then it draws sets the surface on that pixel to the color of the closes seed
I really do not understand why picks those colors everytime: