Autor Tema: Convert png sprite sheet to fpg  (Leído 4291 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado pob

  • Newbie
  • *
  • Mensajes: 2
  • Karma: 1
    • Ver Perfil
Convert png sprite sheet to fpg
« en: Enero 02, 2011, 09:45:20 am »
This will convert a png file of equal sized tiles (x times y) into an fpg.

Código: [Seleccionar]
Program pngtofpg

import "mod_say"
import "mod_map"
import "mod_string"

Process Main()
private
int png_file;
int file_id;
int map_id;
int xloop;
int yloop;
int png_width;
int png_height;
int num_tiles_x;
int num_tiles_y;
int tile_width;
int tile_height;
int gfx_depth;
string filename;
Begin

if (argc<4)
say("Usage:");
say("pngtofpg filename.png numtiles_x numtiles_y");
else
filename=argv[1];
num_tiles_x=atoi(argv[2]);
num_tiles_y=atoi(argv[3]);

png_file=png_load(filename);
png_width=graphic_info(0,png_file,G_WIDTH);
png_height=graphic_info(0,png_file,G_HEIGHT);
gfx_depth=graphic_info(0,png_file,G_DEPTH);
tile_width=png_width/num_tiles_x;
tile_height=png_height/num_tiles_y;

say("Extracting "+itoa(num_tiles_x)+" x "+itoa(num_tiles_y)+" tiles.");
say("Tiles are "+itoa(tile_width)+" x "+itoa(tile_height)+" pixels.");
say("Graphics depth is "+itoa(gfx_depth)+" bit.");

map_id=map_new(tile_width,tile_height,gfx_depth);
file_id=fpg_new();
for(yloop=0;yloop<num_tiles_y;yloop++)
for(xloop=0;xloop<num_tiles_x;xloop++)
map_block_copy(0,map_id,0,0,png_file,xloop*tile_width,yloop*tile_height,tile_width,tile_height,0);
fpg_add(file_id,yloop*num_tiles_x+xloop+1,0,map_id);
end //for xloop
end //for yloop
fpg_save(file_id,filename+".fpg");
end //if
End

Conectado SplinterGU

  • Hero Member
  • *****
  • Mensajes: 12517
  • Karma: 369
  • Sexo: Masculino
    • Ver Perfil
Re: Convert png sprite sheet to fpg
« Respuesta #1 en: Enero 02, 2011, 09:59:34 am »
thanks... maybe the new fonts functions can be used for this... maybe with a minimal modification...
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

Desconectado Sslaxx

  • Newbie
  • *
  • Mensajes: 34
  • Karma: 0
  • Sexo: Masculino
    • Ver Perfil
Re: Convert png sprite sheet to fpg
« Respuesta #2 en: Mayo 26, 2011, 04:35:00 am »
Pardon me for dredging up this old topic, but the code here is broken (due to the forums mangling it maybe?).

http://sslaxx.twu.net/Png2Fpg.prg is what it should be - I think. It compiles and runs, at least. Not tested what it produces, yet.

OK, tested it and it does not work as expected. Sprite 1 seems to be OK, but other sprites appear to be corrupted.
« última modificación: Mayo 27, 2011, 06:16:07 am por Sslaxx »
Stuart "Sslaxx" Moore.