With this version number, you can modify your file format down the road and still write code that will support older versions of the format. You can then read in that number first, and based on that number, process the rest of the file. The only additional value I'd recommend for the header is a version number, and this should be the very first parameter in the file. You read in that line, stash the height and width in the appropriate variables, then read in the rest of the file based on those values. As a simple example, the very first line of your text file could contain two numeric values that are the sprites height and width. You arbitrarily define the format of your header, and then read in the header and use the values read in to read in the rest of the file. This is common to most file formats out there, not just image files. You can incorporate the sprite size into the text file as well using what is referred to as header information. That call is not the same as delete image. So when you are done with that sprite, you must call delete image The brackets are essential, even though they are empty. However, with this dynamic allocation comes more maintainance on your part, because you are responsible for deallocating all memory you allocate. Later, after determining the size of the sprite use image = new char. If you want to have dynamic array size, you have to use a pointer and dynamic array allocation. Nor is it acceptable to pass in the array size as a variable. ASCII art is a graphic design technique that uses computers for presentation and consists of pictures pieced together from the 95 printable (from a total of 128) defined by the ASCII Standard from 1963 and ASCII compliant character sets with proprietary extended characters (beyond the 128 characters of standard 7-bit ASCII). char image is not an acceptable declaration because it does not specify the size of the array. Static arrays have to have their size specified at declaration, and this size has to be static, not dynamic. I'm using less-than as opposed to less-than or equal too because it //starts at 0 and will run to 161 meaning it will run 162 times. ![]() ![]() int sprite_size = (sprite_x +1)*(sprite_y+1) //add one because it //starts at 0 //if this math comes out right, the total size of the array for this //text file (smiley.txt) should hold 162 chars So if it is 9 tall int sprite_y = Chars_Tall_From_File //the value would be 8. Code to open file goes here int sprite_x = Chars_Wide_From_File //0 will count. Char image //an array that contains the char values that will //make up the image
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |