So i got it installed and running, and managed to draw the simple text and variables. Now i am looking at the sprite tutorial.
I am using Genesis Sprite Studio (if there is something better let me know,) and got the file outputed. How would i load this?
Thanks.
SGDK load sprite file
Moderator: Stef
Re: SGDK load sprite file
Are you using a res file to declare the sprite?
Re: SGDK load sprite file
I have not used Genesis Sprite Studio so I'm not sure how much of this post applies to you. Hopefully it helps.
Firstly, check out this exmaple: https://github.com/Stephane-D/SGDK/tree ... ple/sprite
This is what is involved in making it work.
1. Create a PNG file with indexed color (16 color palette) like this one, and put it in the "res" folder:
Each row is an "animation", and each column is a "frame" within those animations. rescomp can detect duplicate frames, so you don't have to worry about loading the same one in memory twice. It also detects blank frames and does not show those either.
2. In that same folder should be a resources.res file, if not create one (filename doesn't matter as long as it ends in .res):
Based on the documentation for the rescomp tool (https://raw.githubusercontent.com/Steph ... escomp.txt) this line will do the following:
I didn't actually test the code I wrote there but it is based on the sprite example with the extra stuff removed. If you compile the sprite example I think it lets you move around and show different animations.
Firstly, check out this exmaple: https://github.com/Stephane-D/SGDK/tree ... ple/sprite
This is what is involved in making it work.
1. Create a PNG file with indexed color (16 color palette) like this one, and put it in the "res" folder:
Each row is an "animation", and each column is a "frame" within those animations. rescomp can detect duplicate frames, so you don't have to worry about loading the same one in memory twice. It also detects blank frames and does not show those either.
2. In that same folder should be a resources.res file, if not create one (filename doesn't matter as long as it ends in .res):
Code: Select all
SPRITE sonic_sprite "sonic.png" 6 6 -1 5
- SPRITE - create a sprite
- sonic_sprite - This is the name of the sprite in your code
- "sonic.png" - The filename/path to the png image to convert to an SGDK sprite
- 6 - Number of columns (there are up to 6 frames per animation)
- 6 - Number of rows (there are 6 animations, one for standing, walking, etc)
- -1 - Use whichever compression it wants
- 5 - Speed for frame advance, the sprite will animate once every 5 frames
Code: Select all
#include <genesis.h>
// Include the generated resource file containing the sprite (whatever_you_named_the_res_file.h)
#include "resources.h"
// Declare an array for your sprites (must be actual sprites and not pointers)
Sprite sprites[2];
int main() {
VDP_init();
// Initialize the sprite engine
SPR_init(256);
// If you want get the palette from the sprite
VDP_setPalette(PAL2, sonic_sprite.palette->data);
// Or from a palette you defined yourself if you want to share the same palette among many sprites
//VDP_setPalette(PAL2, MY_PAL.data);
// Initialize the sprite itself
SPR_initSprite(&sprites[0], &sonic_sprite, 4, 4, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
while(1) {
// Update the sprites in the array, since there is only 1 sprite update 1
SPR_update(sprites, 1);
VDP_waitVBlank();
}
}
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: SGDK load sprite file
Almost perfect except for "6 6" parameters which simply represents the size in tile of the sprite so here for instance the sonic sprite is 6x6 tiles sized (48x48 pixels). The number of frame and number of animation is then automatically computed from the total image size and the basic sprite size =)Grind wrote:I have not used Genesis Sprite Studio so I'm not sure how much of this post applies to you. Hopefully it helps.
Firstly, check out this exmaple: https://github.com/Stephane-D/SGDK/tree ... ple/sprite
...
Based on the documentation for the rescomp tool (https://raw.githubusercontent.com/Steph ... escomp.txt) this line will do the following:
- SPRITE - create a sprite
- sonic_sprite - This is the name of the sprite in your code
- "sonic.png" - The filename/path to the png image to convert to an SGDK sprite
- 6 - Number of columns (there are up to 6 frames per animation)
- 6 - Number of rows (there are 6 animations, one for standing, walking, etc)
- -1 - Use whichever compression it wants
- 5 - Speed for frame advance, the sprite will animate once every 5 frames
Re: SGDK load sprite file
Thanks guys, i got it working. I just modified the example in the sgdk for my sprites.