Thread: Sprite Editor?

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Sprite Editor?

    Now I'm having some bother designing a sprite editor for my engine. I want to save the sprites in a simple format: a grid of numbers. Take this cool dude as an example:

    Code:
    0 0 1 1 1 0 0 
    0 1 0 0 0 1 0
    0 1 0 0 0 1 0
    0 0 1 1 1 0 0
    0 0 0 1 0 0 0
    0 1 1 1 1 1 0
    0 0 0 1 0 0 0
    0 0 1 0 1 0 0
    Now an easy way to solve this would be to find a good (preferably free) sprite editor which saves to a similar format, but I doubt these exist nowadays.

    So basically does anyone have any ideas? I fiddled for a bit in VB but there's no way (that I can see) to 'read' a picture box and... well you can imagine.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    There are programs that can turn pictures into ascii art, which may help you. Perhaps you can make your own sort of paint program? Personally, I think notepad would be optimal.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Me too except I havn't got a colour chart (and it's proving difficult to generate one for some reason).

    My 'artist' has ..........ed already about making sprites using numbers and notepad. As you can see we have great things planned for this engine (NOT)
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Get your artist to export in a specific format (i.e. 8-bit BMP or something easy to parse) and write your own converter into the format your icon loader uses. File formats for just about every image type can be found at wotsit.org.

    Alternately, you could do as skorman00 suggested and write a simple paint program that output in your sprite format. I wrote one of these years and years ago in QBasic and I tried to find it for you, but its buried deeply in my archaic backups and I couldn't find it. I'm not sure what you mean by colour chart. If you're using an 8-bit format (as I assume you are based on your example icon format) then you're using a 256 colour palette which you can set yourself.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Cheers for the input

    By colour chart I meant printing out some sort of list to show which number is which colour. I'm using VGA Mode 13h (I know, I know...) 320x200x256 - but at least I'm learning
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Wow, I thought we were only working with 1's and 0's. I would just do as lightatdawn suggests, and tag any extra info you need to an 8 bit bmp. Remember that bmps store the data upside down, meaning the first byte is the bottom left of the image.
    I'm using VGA Mode 13h (I know, I know...) 320x200x256
    Holy cow, 256 bit color depth?!?! ;-)

  7. #7
    I'll dump a bit of code on you straight from something I found in my backups written at least 5 years ago. Theres enough comments in the code that you should be able to get the gist of how this works, and thus be able to use it to do what you're after.

    IMPORTANT NOTE: This was written in the days of Borland Turboo C++ and thus used the DOS header and lib. You won't be able to actually use this code unless you've got a compiler that supports this. However, everything in the BitMap loading code will work except set_DAC, so the concept of the code is still sound.

    Code:
    /*
    ******************************************
    * EX_BMP.CPP							 *
    *	An example of loading & displaying  *
    *	an 8-bit bitmap					 *
    *									 *
    ******************************************
    */
    
    #include <stdio.h>  //fopen and other i/o stuff
    #include <conio.h>  //used for getch();
    #include <dos.h>	//Used for pretty much everything
    
    char far *Screen;
    
    //Sets the display to VGA 320x200x256
    int init_13h_mode ()
    {
    	union REGS r;
    	r.h.ah = 0;
    	r.h.al = 0x13;
    	int86(0x10, &r, &r);
    	return 0;
    }
    
    //Goes back to text mode
    int init_text_mode ()
    {
    	union REGS r;
    	r.h.ah = 0;
    	r.h.al = 0x3;
    	int86(0x10, &r, &r);
    	return 0;
    }
    
    //This sets a DAC register to a specific Red Green Blue-value
    int set_DAC (unsigned char DAC, unsigned char R, unsigned char G, unsigned char B)
    {
    	outportb (0x3C8, DAC);
    	outportb (0x3C9, R);
    	outportb (0x3C9, G);
    	outportb (0x3C9, B);
    	return 0;
    }
    
    
    int load_bmp (char *filename){
      struct BMPHeader {
      unsigned short bfType;
      long bfSize,
      bfReserved,
      bfOffBits,
      biSize,
      biWidth,
      biHeight;
      unsigned short biPlanes,
      biBitCount;
      long biCompression,
      biSizeImage,
      biXPelsPerMeter,
      biYPelsPerMeter,
      biClrUsed,
      biClrImportant;
      } Header;
      FILE *BMPFile;
    
      unsigned char c, Palette[256][4];
    
      unsigned int offset, lines, paddedWidth;
    
      //This checks for the file
      BMPFile = fopen (filename, "rb");
      if (BMPFile == NULL) {
    	 printf ("Cant open file.");
    	 return 1;
      }
    
      //Read the headerinformation
      fread (&Header, 54, 1, BMPFile);
    
      if (Header.bfType != 19778 || Header.bfReserved != 0 || Header.biPlanes !=1) {
    	 //Not a valid bitmap file - don't display
    	 printf ("Not a valid bitmap.");
    	 fclose (BMPFile);
    	 return 1;
      }
      if (Header.biCompression != 0) {
    	 //Compressed file - don't display
    	 printf ("Compressed file.");
    	 fclose (BMPFile);
    	 return 1;
      }
      if (Header.biBitCount != 8) {
    	 //If the file is other than 8-bit dont read.
    	 printf ("Not an 8-bit bitmap.");
    	 fclose (BMPFile);
    	 return 1;
      }
      if (Header.biWidth > 320 || Header.biHeight > 200) {
    	 //If its larger than 320*200 dont load.
    	 printf ("Size too large.");
    	 fclose (BMPFile);
    	 return 1;
      }
    
      //Ladda paletten
      fread (&Palette, 1024, 1, BMPFile);
      for (c = 0; c < 255; c++)
    	 set_DAC (c, Palette[c][2] >> 2, Palette[c][1] >> 2, Palette[c][0] >> 2);
    
      offset = (100 + (Header.biHeight >> 1)) * 320 + 160 - (Header.biWidth >> 1);
    
      lines = 0;
    
      paddedWidth = Header.biWidth & 0xFFFC;
      if (Header.biWidth != paddedWidth) paddedWidth += 4;
      //Loop for reading lines
      while (lines < Header.biHeight) {
    	 fread (Screen + offset, paddedWidth, 1, BMPFile);
    	 offset -= 320;
    	 lines++;
      }
      fclose (BMPFile);
    
      return 0;
    }
    
    
    
    int main ()
    {
      //Set up a pointer in vga memory at A000:0000
      Screen = (char far *)0xA0000000L;
    
      init_13h_mode (); //initialize VGA mode 13
    
      load_bmp("TEST.BMP"); //load "TEST.BMP"
    
      getch(); //wait for keypress
    
      init_text_mode (); //return to text mode
    
      return 0;
    }
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  8. #8
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Wow thanks! That'll definetely help me a lot, cheers

    *edit*

    I've found Turbo C++ so shouldn't have any probs
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Sprite Editor
    By StuMF in forum C# Programming
    Replies: 0
    Last Post: 07-08-2009, 06:21 PM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. DirectX 9 sprite issue
    By maxthecat in forum Game Programming
    Replies: 9
    Last Post: 05-18-2006, 04:04 AM
  4. Replies: 12
    Last Post: 08-05-2003, 02:16 PM
  5. Replies: 3
    Last Post: 05-12-2003, 05:49 PM