sprite clipping? make colour transparent?

Started by MisterN, February 23, 2013, 12:04:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

I have a sprite sheet that I would rather not split up and I was wondering (because I know SDL can do it, and this is written in SDL) if there was code that could clip sprites. These sprites are 24x32 each. I was also wondering if it is possible to make the background color i gave it transparent in game. Thanks
werg

handsource-dyko

Changing the blue color to transparant is easy, if the image is in 8 bit format. simply check with a graphics program (grafx2 is good for this) what the index value of the blue color is, and then load the png file in your bennu program.

To change the color:



FOR (line_count = 0; line_count < map_info ( <INT fileID> , <INT graphID> , G_WIDTH); line_count++)

      FOR (row_count = 0; row_count < map_info ( <INT fileID> , <INT graphID> , G_HEIGHT); row_count++)

            IF (map_get_pixel ( <INT fileID> , <INT graphID>  ,line_count , row_count ) == wahtever color value blue is))
                map_put_pixel ( <INT fileID> , <INT graphID> , line_count , row_count , 0 )
           END
     END
END



Something like that. But you can copy parts of the map to new maps in memory, to convert the spritesheet into individual images with
map_block_copy.

DCelso

You are saying of setcolorkey. Sorry. Bennu doesnot work with it.
You need do that handsource sais.
Another faster methor is open it in gimp. In layoud menu add transparen add alpha channel. With color selection tool select the blue. And finally delete the selecton and save or export in png.

And for split the images. There is some examples un this forum ti convert this king of images in a fpg in memory needed to make yours games.
Monstruos Diabólicos

"A PAck of classic GAMEs For BennuGD" en desarrollo
http://code.google.com/p/apagame4be/

MisterN

#3
can you show me an example? i saw this
http://forum.bennugd.org/index.php?topic=795.msg11387#msg11387
and i took this code:
function create_fpg_from_tileset(string tilesetname,int num_columns,int num_rows)
private
    tileset;
    tile_width;
    tile_height;
    i,j,k;
    cur_tile;
begin
    tileset=load_png(tilesetname);
    tile_width=graphic_info(0,tileset,g_width)/num_columns;
    tile_height=graphic_info(0,tileset,g_height)/num_rows;
    file = fpg_new();
    cur_tile = new_map(tile_width,tile_height,profundidad);
    for (j=0;j<num_rows;j++)
        for (i=0;i<num_columns;i++)
        k= (j*num_rows+i)+1;
        map_clear(0,cur_tile,0);
        map_block_copy(0,cur_tile,0,0,tileset,i*tile_width,j*tile_height,tile_width,tile_height,0);
        fpg_add(file,k,0,cur_tile);
        end
    end
    unload_map(0,cur_tile);     
    unload_map(0,tileset);
    return file;
end

(what does profunidad mean?)
and i put it in this process
process player_sprite(x,y,)
private
    //sprite information
    int sprite_sheet;
    int line_count = 0; //example: 32 y pixels is 32 lines
    int width = 24;
    int row_count = 0; //exa,ple: 24 x pixels is 24 rows
    int height = 32;
    int sprite[9];
begin
file = create_fpg_from_tileset("testchar.png",3,3);
sprite_sheet = load_png("testplay.png");
graph = 1;
ctype = c_scroll;
    loop
        //keep it alligned with the player
        x = father.x;
        y = father.y-(player_dim_y/4);
        //sprite transparency
        for (row_count = 0; row_count < width; row_count++)
            for (line_count = 0; line_count < height; line_count++)
                if (map_get_pixel(file,graph,row_count,line_count) == rgb(0,148,255))
                    map_put_pixel(file,graph,row_count,line_count,0);
                end
            end
        end
    frame;end
end

and i dont got anything

EDIT:
I changed profunidad to sprite_depth and I made it 16 and it worked :D
werg