SPRITES

SGDK only sub forum

Moderator: Stef

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

SPRITES

Post by Staffan » Thu Jun 22, 2017 10:48 am

Hello again!
I've been messing around with SGDK now for a few hours now and so far Im really impressed. Already have a sprite moving over a surface.
In c64 assembler this took like a week :)

I was wondering if there is a way load bmp into a sprite? So far I have only managed to do the sprites "by coding hand" like writing in the picture in assembler. I can see from examples that this is possible, but I cannot get any of the examples to work as the code and tutorials has changed to much.
Please help :)

I was also wondering were the limitations in using C instead of assembler kicks in. Would you be able to make a platform game with this C library?
How fast is it compared to assembler etc etc, suppose I make a game and run into a dead end, because im using C. That woudnt be fun. :)

User avatar
Stef
Very interested
Posts: 2801
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPRITES

Post by Stef » Thu Jun 22, 2017 11:30 am

Hi Staffan,

Thanks for the nice words about SGDK :)
Of course you can use bmp or png to load up your sprite image :) As tutorials are quite outdated i definitely recommend you to look over the included 'sprite' sample which is a very simple example about how to deal with that.
Basically you should have your resources in a 'res' folder and a .res file declaring them.
Supported resource and format of .res file is described in the bin/rescomp.txt file.

C code is enough for a platform like game, of course you can do more with pure assembly but on MD you can already achieve a lot just with plain C.

This is 2 examples of game wrote in pure C with SGDK :
https://www.youtube.com/watch?v=nfbo0jQEK80
https://www.youtube.com/watch?v=8jDmft2H_Po

And these examples are quite outdated, today SGDK is faster because some methods has been optimized and also because of the new GCC introduced since the last version (1.30) =)

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Thu Jun 22, 2017 1:55 pm

A res file! That explains why the bitmap name wasnt mentioned in the source code of the example! :)

The examples looks awesome! No limitations I guess. 3D I can live without...

User avatar
Stef
Very interested
Posts: 2801
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPRITES

Post by Stef » Thu Jun 22, 2017 6:17 pm

Hehe, yeah the .res file is used to declare any external resource ;)

And the demo games examples from djcc are really impressive for 100% C code, of course he's a good coder and he cleverly designed the code, still it show it's possible to do full and good games with 100% C code :)
About 3D, well SGDK has some methods if you want to play with (flat rendering only) :p

User avatar
Natsumi
Very interested
Posts: 81
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: SPRITES

Post by Natsumi » Thu Jun 22, 2017 8:00 pm

You probably can't really do really fancy effects and complex games such as Sonic or Aladdin, but definitely simpler games could be done. In fact, Sonic Spinball was written completely in C, and I assume its very old compiler, not sure of GCC or something else, but probably not even nearly as good as today's compilers! Definitely for some poking around or unprofessional work, working with pure C wont be a problem, and you can work around the slower nature of C code compared to assembly with just designing better algorithms, that will be faster and more RAM efficient. Though, asm is also very useful thing to know when/if you want to make more complex games, you can pull of some really impressive optimization tricks using it, something that I doubt will ever be possible with just a C compiler.

User avatar
Stef
Very interested
Posts: 2801
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: SPRITES

Post by Stef » Thu Jun 22, 2017 10:17 pm

I would have said that with the previous GCC version but with the last one, the performance start to be really interesting so i think you can even do complex game logic as soon the code and algorithm are good :)

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Fri Jun 23, 2017 12:38 pm

Aha so there was a C compiler back in thoose days. I thought that this community had written the compiler all by themself.
Still impressive do! :)

*********************************************************************************
I tried to compile this:
VDP_loadTileData( &LoloFront, 1, 1, 0);

With the resfile locking like this:
SPRITE LoloFront "sprite/lolo.bmp" 1 1 FAST 5

it says that &LoloFront is undeclared. The sprite example looks to old with completly different functions. Please help me load my sprite :)
Please spritemind people!

User avatar
Grind
Very interested
Posts: 60
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: SPRITES

Post by Grind » Fri Jun 23, 2017 2:31 pm

Do you have an include for "name_of_res_file.h"? Rescomp generates that header based on the .res.

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: SPRITES

Post by Hik » Fri Jun 23, 2017 2:42 pm

This is the way I usually declare a sprite in the .res file;

Code: Select all

SPRITE bubble_sprite "bubble1.png" 1 1 -1 1
With this just make sure that the image you're using is indexed for 16 color palette (I usually convert it in gimp)
and that its in the same directory as the res file
(or use a slash if you have it in a folder next to the .res file which I usually keep in the res folder)

Then in the actual code you can make a sprite array and use SPR_addSprite() ;

Code: Select all

Sprite *sprites[10]; //10 sprites

sprites[0] = SPR_addSprite(&bubble_sprite, posx, posy, TILE_ATTR(PAL0, TRUE, FALSE, 0));
And yeah like grind says remember to include the .h file

Code: Select all

#include <genesis.h>
#include "sprite.h"
...
sprite.h

Code: Select all

#ifndef _RES_SPRITE_H_
#define _RES_SPRITE_H_

extern const SpriteDefinition bubble_sprite;

#endif // _RES_SPRITE_H_

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Fri Jun 23, 2017 9:27 pm

Thank you!
It almost worked...
He now loads image but with the wrong offset.

I now see that the tutorial is still worth to look at. I used VDP functions I saw on some other site even for sprite and not just for background,
but now I use SDR for sprite.

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Fri Jun 23, 2017 10:34 pm

Would appreciate this. The sprite loads in the middle of sprite and in wrong order... I think I do exactly as the sprite tutorial now.

Its a 24*24 pixel bitmap.

SPRITE LoloFront "sprite/lolo.bmp" 3 3 -1 1
---------------------------------
SPR_init(16, 256, 256);
sprites[0] = SPR_addSprite(&LoloFront, 0, 0, TILE_ATTR(PAL1, FALSE, FALSE, 0));
// VDP process done, we can re enable interrupts
SYS_enableInts();

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: SPRITES

Post by Hik » Fri Jun 23, 2017 11:31 pm

There's documentation that you can refer to in older SGDK versions, you can look it up with the forum search in the top right
When you find the doc folder, open the html folder and click on the index file and then go through the lists like the file list
Also look for the rescomp.txt file it has better details about the tools and what the numbers in the sprite res file are for
If you're not sure about something like using certain functions you can also look that up in the forum or post and ask about it

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Sat Jun 24, 2017 9:16 am

Thanx,
The documentation works fine, but theres just a list of fuctions and what they do.
Thats good, but its the same information I have in Visual Code itself. As soon as I start typing visualcode suggest a function and I can se a list of all available, so thats pretty good. :) I can also click "goto definition" where I can se the description of the input variables. I have still find zero information on why he loads the sprite in the wrong order, and skips the first three squares.

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Sat Jun 24, 2017 11:32 am

Original sprite:
lolo.gif
lolo.gif (1.04 KiB) Viewed 1690 times
How he loads it:
test.gif
test.gif (1.53 KiB) Viewed 1690 times
I really want to be one of those guys that asks about everything on the forum...but Im stuck here. Ive been checking the sprite tutorial quite alot now. I just had alot of time with this this weekend. This is not the usual me, with two kids :)

User avatar
Staffan
Very interested
Posts: 57
Joined: Wed Jun 14, 2017 2:33 pm

Re: SPRITES

Post by Staffan » Sat Jun 24, 2017 2:33 pm

Ok, I used a 16 color bitmap whick "kindof" worked. But with png it worked flawlessly :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests