GameMaker Сreating objects from a template from a picture

sinigrimi

Member
Can I draw in Photoshop a map with objects and so that gms2 reads them and creates them on these peksels? let's say I draw a lot of patterns and and objects spawn in these places, this can greatly simplify my task

(screenshot below)
 

Attachments

Joe Ellis

Member
You can make a script which reads every pixel of an image, and does a certain thing depending what color each pixel is. It's very slow, but could be ok if you do it gradually, like read so many pixels per step.
Look up surface_get_pixel
 

sinigrimi

Member
You can make a script which reads every pixel of an image, and does a certain thing depending what color each pixel is. It's very slow, but could be ok if you do it gradually, like read so many pixels per step.
Look up surface_get_pixel
I read the help about it and as I understand it is highly likely that it will be in the waste of time. Thanks!
 
R

robproctor83

Guest
If you wanted to do full art like that, then yea just use the room editor. You can also use other tools like Tiled and export to GM if you wanted. However, if you needed to load up predrawn maps and convert them to rooms you would make each pixel a cel. So in your drawing you wouldn't have a full door object drawn out, but instead an orange pixel which represents a door. You would loop over every pixel of the image and then do a lookup on a corresponding list that relates what colors are what objects and then create an object accordingly. It's not overly complicated but unless you have a specific reason for it then there is no point.
 

Alexx

Member
If you are looking for a way to hold many level designs, I have an example that uses a simple text file.
Different letters and numbers are used for each cell type.
Objects are then created in the room based on this text file.
If you'd like an example, let me know.
 

sinigrimi

Member
If you wanted to do full art like that, then yea just use the room editor. You can also use other tools like Tiled and export to GM if you wanted. However, if you needed to load up predrawn maps and convert them to rooms you would make each pixel a cel. So in your drawing you wouldn't have a full door object drawn out, but instead an orange pixel which represents a door. You would loop over every pixel of the image and then do a lookup on a corresponding list that relates what colors are what objects and then create an object accordingly. It's not overly complicated but unless you have a specific reason for it then there is no point.
when I say rooms, I mean rooms like in Isaac ... in fact, I use only one room in which "rooms" are created using the generation code
 

sinigrimi

Member
If you are looking for a way to hold many level designs, I have an example that uses a simple text file.
Different letters and numbers are used for each cell type.
Objects are then created in the room based on this text file.
If you'd like an example, let me know.
it would be interesting to experiment with this
 

Alexx

Member
Here's an example code for parsing a file:
Code:
/// @description Process Data
num=0;
file=file_text_open_read("level.txt");//open file for reading
while (!file_text_eof(file))//loops until end of file
{
    str[num] = file_text_read_string(file);//add each line
    file_text_readln(file);//move to next line
    num++;
}
file_text_close(file);//closes file
grid_size=32;//this how big our sprites are
//create a loop for however many lines
for (i = 0; i < num; i += 1)
{
    line=(str[i]);//get line i from array
    line_width=string_length(line);
   //line_width=string_width)
    for (j = 0; j < line_width+1; j+= 1)
    {
    //check each position, create appropriate block
        if string_char_at(line, j)=="#" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_wall);
        if string_char_at(line, j)=="." instance_create_layer(16+j*grid_size,16+i*grid_size,"Hole",obj_hole);
        if string_char_at(line, j)=="$" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_block);
        if string_char_at(line, j)=="@" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_player);
    }
}
And an example text file contents:
Code:
 #####
 #@  ##
 #.$  #
 #  # #
 #    #
 ######
The above assumes you have an included file level.text.
 
Last edited:

sinigrimi

Member
Here's an example code for parsing a file:
Code:
/// @description Process Data
num=0;
file=file_text_open_read("level.txt");//open file for reading
while (!file_text_eof(file))//loops until end of file
{
    str[num] = file_text_read_string(file);//add each line
    file_text_readln(file);//move to next line
    num++;
}
file_text_close(file);//closes file
grid_size=32;//this how big our sprites are
//create a loop for however many lines
for (i = 0; i < num; i += 1)
{
    line=(str[i]);//get line i from array
    line_width=string_length(line);
   //line_width=string_width)
    for (j = 0; j < line_width+1; j+= 1)
    {
    //check each position, create appropriate block
        if string_char_at(line, j)=="#" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_wall);
        if string_char_at(line, j)=="." instance_create_layer(16+j*grid_size,16+i*grid_size,"Hole",obj_hole);
        if string_char_at(line, j)=="$" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_block);
        if string_char_at(line, j)=="@" instance_create_layer(16+j*grid_size,16+i*grid_size,"Instances",obj_player);
    }
}
And an example text file contents:
Code:
 #####
 #@  ##
 #.$  #
 #  # #
 #    #
 ######
The above assumes you have an included file level.text.

an interesting way, but it only complicates the task, I manually entered 400 lines in two hours (although now all this needs to be added to ds_list, LOL), and here you have to draw with signs and additionally double-check. Anyway, thank you, it was informative for me
 
Top