Created Sprites Not Being Assigned Properly

W

whale_cancer

Guest
PREAMBLE: Apologies for this post so soon after my last, but the last post was due to me having created a hacky work around for the problem, forgetting I had, and then having that hack work as long as I didn't use transparent or semi-transparent tiles.

WHAT I AM DOING: I have a script that performs 3 steps using nested loops.

First, it creates a 1024 x 1024 surface onto which I draw 64 128x128 backgrounds.

Code:
//Create a large surface to hold all of my constituent ppu tables
surface = surface_create(1024, 1024);
surface_set_target(surface);
draw_clear_alpha(c_black, 0);

//Draw each background onto the surface
for (w = 0; w < 8; w += 1)
{
    for (h = 0; h < 8; h += 1)
    {
        draw_background(asset_get_index('ppu_'+string(w)+string(h)), w * 128, h * 128);
        show_debug_message('Adding ppu_'+string(w)+string(h)+' at '+string(w * 128)+','+string(h * 128))
    }
}

sprite_save(sprite_create_from_surface(surface,0,0,1024,1024,false,false,0,0),0,'ppu_master.png')
As you can see, I output this surface as a .png file. The file looks as I would expect.

Next, I create a 2d array which is meant to contain sprites derived from my surface. These sprites are 16 x 16 and thus my surface produces 4096 sprites, or, understood as a 2d array, an array of 64 width and 64 height with each entry hold a sprite. I realize this may be memory inefficient, but this is only for a map editor and I notice absolutely no slowdown.

Code:
//Create ppu sprites
for (w1 = 0; w1 < 8; w1 += 1)
{
    for (h1 = 0; h1 < 8; h1 += 1)
    {
        for (w2 = 0; w2 < 8; w2 += 1)
        {
            for (h2 = 0; h2 < 8; h2 += 1)
            {
                ppu_table[(w1*8) + w2,( h1*8) + h2] = sprite_create_from_surface(surface, (w1 * 128) + (w2 * 16), (h1 * 128) + (h2 * 16), 16, 16, false, false, 0, 0);
                show_debug_message('Adding sprite to ppu_table['+string((w1*8) + w2)+','+string((h1*8) + h2)+']')
            }  
        }
    }
}
UPDATE: I have now outputted ppu_table as a sprite strip, and it looks as I would expect. Here is part of the strip, imgur won't let me post the bizarre image size of such a strip.

I then create a series of buttons which, when assembled, should look exactly like the surface I have created
Code:
//Create ppu buttons
for (w1 = 0; w1 < 8; w1 += 1)
{
    for (h1 = 0; h1 < 8; h1 += 1)
    {
        for (w2 = 0; w2 < 8; w2 += 1)
        {
            for (h2 = 0; h2 < 8; h2 += 1)
            {
                with instance_create(room_width + 160 + (w2 * 16) + (w1 * 128), (h2 * 16) + (h1 * 128), obj_tileBrush)
                {
                    sprite_index = other.ppu_table[(other.w1 * 8) + other.w2, (other.w1 * 8) + other.h2];
                    show_debug_message('Assigning sprite to obj_tileButton of ppu_table['+string((other.w1*8) + other.w2)+','+string((other.h1*8) + other.h2)+']')

                    brush_background = asset_get_index('ppu_'+string(other.w1)+string(other.h1));
                    brush_left = other.w2 * 16;
                    brush_top = other.h2 * 16;
                }
            }  
        }
    }
//Free and reset the surface

surface_reset_target();
surface_free(surface);
}
THE PROBLEM: The problem is that the resulting buttons DO NOT look like the surface I have generated. Instead, the first 8 columns of buttons (which should be the first 128 x 1024 sliver of the surface I created) is instead the first 128x128 of the surface repeated 8 times. The next 8 columns are just the 128x128 part of the surface that starts at 128, 128 on the surface. Likewise, the next 8 columns after that are the 128x128 part of the surface that starts at 256, 256 on the surface and so on, and so on. This screenshot should hopefully illustrate what is happening.

I know that this part of the code...

Code:
                    brush_background = asset_get_index('ppu_'+string(other.w1)+string(other.h1));
                    brush_left = other.w2 * 16;
                    brush_top = other.h2 * 16;
...is working as intended, as - despite the sprite of the brush tile being incorrect - I can use it to correctly set my brush attributes and paint tiles.

I think this must have to do with...

Code:
sprite_index = other.ppu_table[(other.w1 * 8) + other.w2, (other.w1 * 8) + other.h2];
But my debug information suggests that these are being assigned correctly. Please help GM forums, you are my only hope!

Compile Window Dump
.
 
Last edited:
Top