• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker buffer based palettizing? game currently really slow.

S

Shadowblitz16

Guest
does anybody know how to make a my palette_create and tileset_create functions faster?
right now it takes about 2 minutes to load everything before the game starts to draw.

I'm trying to make custom palettized tile drawing so I can make a zelda game.
currently its coming along very well but recently when I changed it to hold 256 palettes and tilesets it became horribly slow.

I heard that buffers were alot faster then "surface_getpixel" If this is true it would increase the startup speed dramatically.

Code:
/// @description Editor Create Event
// You can write your code in this editor

for (var i=0; i<256; i++) palette[i] = palette_create();
for (var i=0; i<256; i++) tileset[i] = tileset_create();

tile = 0;
pal  = 0;
col  = 0;
Code:
/// @desc palette()
/// @param *image

var image = -1;
var data;

if (argument_count == 1) image = argument[0];

if (image == -1)
{
    data[$0] = make_color_hex($000000);
    data[$1] = make_color_hex($FBD38A);
    data[$2] = make_color_hex($CD7320);
    data[$3] = make_color_hex($713020);
    data[$4] = make_color_hex($10AA41);
    data[$5] = make_color_hex($084928);
    data[$6] = make_color_hex($1882FB);
    data[$7] = make_color_hex($004182);
    data[$8] = make_color_hex($700028);
    data[$9] = make_color_hex($F81858);
    data[$A] = make_color_hex($8888A0);
    data[$B] = make_color_hex($283050);
    data[$C] = make_color_hex($000000);
    data[$D] = make_color_hex($000000);
    data[$E] = make_color_hex($000000);
    data[$F] = make_color_hex($000000);
}
else
{
    var i = 0;
    var sprite = sprite_add(image,0, false, false, 0, 0);
    var iw     = sprite_get_width(sprite);
    var ih     = sprite_get_height(sprite);
   
    for(var iy=0; iy<ih; iy++)
    for(var ix=0; ix<iw; ix++)
    {
        if (i >= 16) continue;
        var color   = draw_getpixel(ix, iy);
            data[i] = color;
        i++;
    }
}

return data;
Code:
/// @desc new_tileset()
/// #param *image
/// @param *palette


var pal = -1;
var img = -1;
var data;

if (argument_count >= 1) img = argument[0];
if (argument_count >= 2) pal = argument[1];

if (pal == -1) pal = palette_create();
if (img == -1)
{
    for (var i=0; i<20480; i++) data[i] = 0;
}
else
{
    var i = 0;
    var sprite = spr_example; //temporary
    var iw     = sprite_get_width(sprite);
    var ih     = sprite_get_height(sprite);

    var surf   = surface_create(iw, ih);
    surface_set_target(surf);
    draw_sprite_part(sprite, 0, 0, 0, 160, 128, 0, 0);  

    for(var iy=0; iy<ih; iy++)
    for(var ix=0; ix<iw; ix++)
    {
        if (i >= 20480) continue;
   
        var color   = surface_getpixel(surf, ix, iy);
        var index   = color_closest_pal(color,  pal);
            data[i] = index;
        i++;
    }
    surface_reset_target();
    sprite_flush(sprite);
}

return data;
 
S

Shadowblitz16

Guest
read pixels from an image and get the INDEX of the closest color in the palette
the problem is that I have a 256 length array of tilesets that call this code.
 
Top