SPRITES tutorial on SGDK : need to understand

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
tama
Interested
Posts: 17
Joined: Wed Aug 12, 2015 9:13 am
Location: Lyon, France

SPRITES tutorial on SGDK : need to understand

Post by tama » Sun Aug 30, 2015 9:55 pm

Hello,
I'm working on the SGDK Sprites tutorial.
As an exercise, I was trying to replace sonic by Marco from Metal Slug and backround planes A and B by Metal Slug background.

Unfortunately, I need more clues about this coding because I don't really understand.
As a result, I get background and sprite that are not displayed correctly.
When I do action with my sprite (jump, etc), the background gets differents.

=> Here are the code files : main.c+gfx.res+gfx.h <=
=> I tried to undestand the main code but I need help to learn more and to progress <=

Screen shot of what I get in emulator
Image

About the background,
> if I run the program without the sprite, backround is displaying correctly, except if its size get too big :
* display OK when both planes A and B are up to 760x224.
* from 768x224, it's not displaying correcty, as in the picture above. The bigger the size is, the worse it gets. It looks like there are some tiles a little bit everywhere.
>to see it correctly when runing the progam with the sprite, I perhaps have to reduce the background size ? But it seems to be above the limit size so it shouldn't be a problem

=> This problem about background is perhaps a memory problem ?

=> about the sprite, how can I get it right ?
moves to set are : LEFT and RIGHT to walk / UP to shoot / A, B, C to jump
(I did let the original file's physics at first because I just wanted to get dispaly first)

Here is the sprite sheet
(I set it, as I think it's correct, with same size for each frame / here it is 8x8 tiles / but frames are perhaps not correctly centered)
Image

background planes A and B (760x224) :
Image

Image

Thank you,
TAMA

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

Re: SPRITES tutorial on SGDK : need to understand

Post by Stef » Mon Aug 31, 2015 8:55 am

There is good chance that you are running out of vram.
You reserve 256 tiles for the sprite engine which are taken from the high vram tiles area part:
You can see in sprite_eng.c that tile index for sprite engine is calculated by doing index = TILE_FONTINDEX - size;
If you 'ind' variable goes higher than "TILE_FONTINDEX - size" after you loaded both BG plan then your BG tiles get mixed with the ones used for sprites, which might be your problem.

tama
Interested
Posts: 17
Joined: Wed Aug 12, 2015 9:13 am
Location: Lyon, France

Re: SPRITES tutorial on SGDK : need to understand

Post by tama » Mon Aug 31, 2015 8:30 pm

Difficult to understand for me...
Is there a way to solve that without reducing the size of my background ?

--------------------------------------------------------------------------
Total number of tiles :
--------------------------------------------------------------------------
Plan A + B :
2x 760 x 224 pxl
=> tiles => 2x 95 x 28 = 2x 2660 = 5320 tiles

Sprite sheet :
728 x 224 pxl
=> tiles => 91 x 28 = 2548 tiles
--------------------------------------------------------------------------
TOTAL = 5320 + 2548 = 7868 tiles
--------------------------------------------------------------------------

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

Re: SPRITES tutorial on SGDK : need to understand

Post by Stef » Tue Sep 01, 2015 8:25 am

If you assume that simple calculation, of course your background won't fit at all in the VRAM (you have only a bit more than 1400 tiles fitting in the VRAM). What i really need to know is the value of your 'ind' variable after you loaded the 2 backgrounds (you have many duplicated tiles so it should not be that much).

You can use GensKmod for easier debug, just display the value in the output message of GensKMod by using KDebug_xxx(..) methods of SGDK.
It's an easy way to have some logs from your execution and understand what happen.

tama
Interested
Posts: 17
Joined: Wed Aug 12, 2015 9:13 am
Location: Lyon, France

Re: SPRITES tutorial on SGDK : need to understand

Post by tama » Tue Apr 03, 2018 10:51 pm

Hi, I'm back !
I didn't continue to try programming with SGDK until now... shame on me.

So, because it's very difficult for me to understand thing (abstract things), I started from the begining and used again the SPRITE sample from sgdk134.
I began to remove everything I didn't want to study to get the code clearer. So I removed the animations.

I only kept the scrolling and Sonic left/right move (without the animation so only 1 sprite is used).
My goal is to make an infinite scrolling while sonic is moving.

FIRST, I want to display informations about the positions and other variables, on screen to understand better what happens.
But as I move, the text is moving when using VDP_drawText, so it seems to be on plan A.
I wanted to display the text on Window Plan to have a static text but nothing appears. Also I saw on a forum that the Window Plan is a static version of Plan A so impossible to display Plan A and Window at the same time ?
Should I display my text by following the camera position ? But text display is based on tile position and not pixel position...

SECOND, I can't display the variables. Is it because I have to convert them into char or str ? How to do it exactly ? Syntax ?

Questions that seem to be to easy but I need help with simple words.
Thank you :)

Post Reply