123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|631|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Good way to handle sprites?

Sat, 13 Jan 2018, 22:52
Charles

Good way to handle sprites?


Hi, everyone.

What is a good way to store sprite data for an arcade-style game?

I realize that's a broad question. So, to be more specific: I have a character that can face in 8 directions. He is made up of two sprites, one for his legs, and one for his upper body. This is because he should be able to aim independently of the direction in which he's running (as in games like Smash T.V. and Shock Troopers). Moreover, the individual images vary a great deal in their proportions; if I were to store them in a standard tile map, there would be a lot of wasted space in some of the images. Of course, there will also be enemies, projectiles, etc.

So, I know I'll need to store information about each image, including coordinate offsets. But this is my first time trying to code something like this and I'm having trouble even defining the problem. I sense that I'll end up doing something very stupid if I don't first consult the veterans (that's you) for advice.

Naturally, I'd like to keep things tidy, readable and easy to modify as I progress. Should I put the required information about each sprite into a data statement, and read from that into an array? How would you organize something like this?

Thanks in advance for any help you can offer.
Sat, 13 Jan 2018, 23:22
Dabz
Mmmmm Not sure how complicated your sprites will be in terms of making up a character/enemy, but, if it were me... I'd probably write a tool to do the job.

Basically, all your sprites will share the same type of data, and writing/editing this data in DATA statements will be a 'mare, be it an id, drawing position from the main player/enemy drawing origin etc

If you built a little editor, you could import each sprite, fill in/edit the properties, even position each bit so it automatically works out the offset from your characters main drawing position (You could use onion skinning with other sprites so it will look spot on)... Then, when your happy, just export all your individual sprites to an atlas with a corresponding file with all the data in (Be it in XML file or JSon or whatever) for each sprite.

Then, in your game, just write a loader, and voila.

Thats what I would do anyway

Dabz

-=-=-
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 8Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit
Sun, 14 Jan 2018, 05:38
GfK
I'd go with the sprite atlas option as well.
Sun, 14 Jan 2018, 06:04
Jayenkai
I'm far too lazy for that shit, and just stick with boxes, although my games aren't exactly art-intensive!!

But, yeah, if you can design your own tool to organise the sprites and output just the right information, then you can tweak it to perfectly suit your target.
Remember, though, that systems seem to work better if you draw batches of sprites from the same texture*, instead of getting it to switch between different textures all the time. Try to keep similar items on a single sheet, so that when it comes to drawing them, you aren't jumping about too much.

(* Dependent on the engine you're using, but good practice)

-=-=-
''Load, Next List!''
Sun, 14 Jan 2018, 07:49
Charles
Thanks very much for the replies. I'm using either Blitz Basic or PureBasic (will probably end up being the latter, but they're very similar). Also, I'm not familiar with JSon and XML. I'm not an experienced coder, but I've written some simple games and tools using BB and PB.

Hmm. I'll have to decide whether or not the quantity of images in my game will justify the effort put into writing a tool. For trial purposes, I can manually locate the offsets for my images right in my graphics editor and keep them (along with the other info) in a spreadsheet, and then convert all of it to whatever format is needed.

Once I have the data in a readable format, what's a good way to handle it in code? Structured array?

Thanks again.
Sun, 14 Jan 2018, 14:44
TomToad
JSon and XML are both good general file formats. XML is more powerful, but also more complicated. Either will require implementing a parser if the language doesn't include one. Not sure about PureBasic, but I know that Blitz Basic doesn't. If you check the code archives in mojolabs.nz, you can find a JSON parser and an XML parser.

Personally, for something as simple as a sprite atlas, I would just roll my own format. Probably in a CSV file. Each sprite on it's own line with x, y, width, and height separated by commas.
You didn't say which version of Blitz Basic you would be using, here is some code for parsing a CSV file in BlitzMax

Blitz3D and BlitzPlus would not be much different except you would need to loop through the type list to find the desired label instead of a map, and you would need to create a Split() function to split the lines.
Sun, 14 Jan 2018, 15:13
rockford
I really think you're over-complicating this.

Just use the sprites as either animation strips or individually. I doubt there's too much wasted space in the images and even if there is, so what? We're not using Speccys with 48Kb nowadays. I'm not saying we shouldn;t care about file sizes, but I doubt a few character sprites will use up masses of memory.

JSON and XML and other routines just seem like overkill to me. Just make sure that each image in the animation strip are of the same size and in the right position based on their required placement on the body, then just draw the correct animation frame in the same place every draw.
Sun, 14 Jan 2018, 15:15
GfK
I used Texture Packer Pro. Not free, but well worth it.

Then just a case of writing a loader/parser for whatever version of Blitz you're using. I used Blitzmax which there was already and XML module for which took 90% of the pain out of it.

https://www.codeandweb.com/texturepacker
Sun, 14 Jan 2018, 19:07
therevillsgames
I use Texture Packer too, you can use it for "free" but you dont have all the features enabled
Sun, 14 Jan 2018, 19:13
Charles
Thanks all for the suggestions. Much appreciated.