Page 1 of 2

Template for Games / Sprites

Posted: Mon Dec 17, 2018 7:55 pm
by Kilo
Hey guys...

Does anywhere exists a template where I can create a sprite game?

Well... I only used tiles in the past. Now I would like to create a game where I need a sprite. The best demo I found was Whack a Mole because of the cursor movement.
Instead of using the hand as a cursor I would like to use an own one. But in the path there is only a .psd and a .raw file for the cursor which I can't edit and convert with gconvert.exe like I did with tile based games.

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 8:19 pm
by nicksen782
Anything can be a sprite. If you just want something like an arrow for a cursor then you just need 1 tile.

Set your sprite bank correctly and you don't even need to have a dedicated sprite tileset. You can have up to 4 sprite banks (separate tilesets for sprites) and the best part is that you can use each without having to switch out the tileset. You just need to indicate which sprite bank you want for whatever sprite you draw.

Code: Select all

// In your game init:
SetTileTable(bg_tiles);
ClearVram();
SetSpritesTileBank(0 , sprite_tiles   ); // 0 -- SPRITE_BANK0
SetSpritesTileBank(1 , bg_tiles   );     // 1 -- SPRITE_BANK1

// Loose code example for drawing sprites:
sprite_bank=SPRITE_BANK0; // (can use 0,1,2,3)

// Map it.
MapSprite2( nextSpriteNum, cursortile,
	( ( xDir == 1 ? SPRITE_FLIP_X : 0 ) | ( onBack == 1 ? SPRITE_FLIP_Y : 0 ) ) | sprite_bank
);
// Move it.
MoveSprite(nextSpriteNum, x, y, width, height);
// Adjust next sprite number.
nextSpriteNum += (1 * height);
Note that you can change the tilebank and I set the spritebank 1 to be bg_tiles (background tiles). Your tile can be from either tileset. It does not matter.

Does this help?

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 8:26 pm
by Kilo
Thank you...

So it doesn't matter what tileset or picture I use? But why does the program knows what pixelcolor is the sprite and what is the backgroubd of the sprite in order to make it transparent?

Can I only use 1 .png picture, convert it and set in the code what "tile" in the picture is my sprite?

Sorry... I'm very confused about this 😁

What I asked for is an empty game where in the data folder is a .png file where you can paint your tiles, backgrounds and sprites like you want and convert it to .inc
And then load it in the game.

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 8:44 pm
by nicksen782
I must not be understanding you. If you can wait about 6 hours I could whip up an example game where you would have bg tiles and sprite tiles that you can run through gconvert. Is that what you meant? Or do you just need an example image and an example .xml gconvert file? I could do either or both.

If you want, you can use the same image for all background tiles and all sprites. You would just run gconvert multiple times to generate the different tilesets based on the tilemaps you specify. For example, my bg tile image has my background tiles but also has tiles that end up in a separate tileset. I use them for my game logo. Only the tiles that are used by a tilemap are included in a tileset.

The default "transparent" pixel color is 0xFE although for a game I'm working on I set it to black. KERNEL_OPTIONS += -DTRANSLUCENT_COLOR=0x00

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 8:52 pm
by Kilo
Ahh okay...
Didn't know this with the transparency.

Wow... that would be very very cool if you could make me a template like you said.
That would help! Thank you.

But take your time... it's 9pm here. Die Hard on the tv and then time for bed 😁
I would take a look tomorrow. 👍👍

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 8:55 pm
by Jubatian
Just dropping this if it could help: If you have Gimp, keep in mind that it can export images as header files. My modes often rely on it to get images converted for them. So the point is that Gimp spits out a header file, if you ask it to save a palettized image, then the main image array is 8 bits. So you could just grab that (even as-is for Mode 3 and similar 8 bit modes if you had a properly ordered Uzebox palette in Gimp), or write small pieces of code converting to whatever format fits you (especially useful for getting tilesets for weird code-tile modes).

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 9:21 pm
by Kilo
Yeah... I tested Gimp years ago but for me it's easier to use simple paint shop pro and gconvert.
Im very fast with it.

The most difficult thing for me is like I said how to work with sprites.
My "template" for every game was until now Megatris.
There I changed the graphics.png like I wanted and converted it.
The movement of the tiles in the code was self explained.

Now I am looking for a similar solution for sprites.

Re: Template for Games / Sprites

Posted: Mon Dec 17, 2018 11:29 pm
by nicksen782
@Jubatian: GIMP can output... code? Is this something like how Tile Studio could do that?

@Kilo: I'll attach something tonight to this thread. This will be simple but will contain the following: Source images, gconvert xml files, demo code that can switch tilesets and work with multiple sprite banks. I'll just have sprites moving around in the demo. I'm assuming video mode 3 here. You should be able to see the relationships between images, xml, and how to operate them with the built-in Uzebox stuff.

I actually had a demo of this in place for something else... Now I have a great reason to finish it! But for now, I'll help you with this template.

Should be fun!

Re: Template for Games / Sprites

Posted: Sat Dec 22, 2018 3:35 pm
by Jubatian
nicksen782 wrote: Mon Dec 17, 2018 11:29 pm@Jubatian: GIMP can output... code? Is this something like how Tile Studio could do that?
Yup, I am using it all the time. You can find it in the export options, along with the other file formats (there are two options, the export to C source code header is the easier to handle of the two). All my modes rely on it for images since it is just very easy to get stuff converted to the appropriate format this way.

Re: Template for Games / Sprites

Posted: Thu Jan 24, 2019 4:48 pm
by Strela_17
Well color me surprised, I'll go and download Gimp again if it is able to put out code. I've been losing time and motivation when doing image conversions lately, and I don't want to give up on my project because of some petty BS code issues.