dealing with matrices (arrays)

SGDK only sub forum

Moderator: Stef

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Fri Jul 06, 2018 12:03 am

thanks for your advices, stef.

I read a little about C, now I know how to make a variable global. :wink:

also, I can do what I want to do at this part: two levels and a way to add more levels. thanks again.

here is my small contribution so far, a small platformer example with a simple big map scroll and collisions.

it could not be the clever way to do, but at least it is working. :D

all the project with some comments in english and portuguese.
https://drive.google.com/file/d/15F-3YR ... sp=sharing

the transition between levels needs a lot of adjustments.

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Sat Jul 07, 2018 1:53 am

I get some trouble when adding some music to the game, I copy + paste the code from sprite example, also copy + paste same vgm music etc. then my game only runs on fusion emulator with music and stops to work on gens (black screen). when I comment the code from the music "//SND_startPlay_XGM(musica);" the game works fine on both emulators. any solution? :?:

The code of the game is the same one I added a link on the last post, I just added the line
"SND_startPlay_XGM(musica);"
where musica refers to the same vgm music from the sprite example.

Gens emulates better than fusion, as the game with music did not play on my mega drive. Withouth music it played. :mrgreen:

EDIT: problem with the music solved. I added sound fx, the jump sound, then the game worked 100% and the music played on gens emulator. Later I will test again on mega drive. :D



also I wanna know if it is possible to destroy a sprite, then create another using the free space that it left on vram tiles and change the animation.

the order I did the commands

1- sprites[1] = SPR_addSprite(&inimigo1, fix32ToInt(inimigoX[0]), fix32ToInt(inimigoY[0]), TILE_ATTR(PAL3, TRUE, FALSE, FALSE)); //add a sprite with animation inimigo1, ok

2- SPR_setVRAMTileIndex(sprites[1],200); //uses the tile index 200, ok

to test the way to destroy the sprite and put another with other animation I press button A, then these commands are executed:

3- SPR_setNeverVisible(sprites[1],TRUE); //truly hides the sprite

4- sprites[1] = SPR_addSprite(&inimigo2, fix32ToInt(inimigoX[0]), fix32ToInt(inimigoY[0]), TILE_ATTR(PAL3, TRUE, FALSE, FALSE)); //add a sprite with a new animation inimigo2, ok

5- SPR_setVRAMTileIndex(sprites[1],200); //goes to the same tile index vram position=200, ok

but if I keep pressing A button, I thought it will clean/delete with never visible, but then the game crashes.

what could I do to avoid the game crashes?

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

Re: dealing with matrices (arrays)

Post by Stef » Sat Jul 07, 2018 1:47 pm

Well done ! To delete / remove a sprite you need to use SPR_releaseSprite(..) method :) Here you were just hiding it, it was always allocated internally (still that doesn't really explain the crash).

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Sat Jul 07, 2018 2:41 pm

Stef wrote:
Sat Jul 07, 2018 1:47 pm
Well done ! To delete / remove a sprite you need to use SPR_releaseSprite(..) method :) Here you were just hiding it, it was always allocated internally (still that doesn't really explain the crash).
as it is just hiding the sprite, maybe the crash (game stop and hide all sprites) is that it passes the max limit of 16 sprites that is set at "SPR_init(16, 256, 256);".

I will take a look at this "SPR_releaseSprite(..)" thanks

EDIT: with "SPR_releaseSprite(..)" it works 100% ok. really nice.

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

Re: dealing with matrices (arrays)

Post by Stef » Mon Jul 09, 2018 9:50 am

Oh 16 sprites, indeed you were probably quickly reaching the limit then ;) Glad you fixed it =)

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Mon Jul 09, 2018 3:43 pm

Stef wrote:
Mon Jul 09, 2018 9:50 am
Oh 16 sprites, indeed you were probably quickly reaching the limit then ;) Glad you fixed it =)
Thanks.

I was just testing the sprite engine.

Now I am trying to move enemies over the screen. My code needs lots of improvements.

When I used BEX, I could control 6 enemies + player + 1 bullet that player shoots. Using a loop to make the enemies move.

Now, with SGDK, unfortunately, I can control only 4 enemies + player + 1 bullet, with a little slow down. The better I can get with no slow down is: 2 enemies + player + 1 bullet.

Even just showing more sprites with that code that I posted here, the limitations are the same 4 sprites.

Maybe I am using numbers too big to handle at the code as I am using lots of "<<6" and "<<11".

EDIT: or I am not using the engine correctly with the FIX32 and so on. I have to take a look at this. I will study carefully the sprite example. :)

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Tue Jul 10, 2018 2:23 am

my problem was so simple to solve, it was the way I was using rescomp, I setted everything to BEST, when I changed to FAST, I get out of problems. :D

now the game runs ok, even better: 8 enemies + bullet + player; I will see how many enemies I can add with just one loop to control everything. 8)

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

Re: dealing with matrices (arrays)

Post by Stef » Tue Jul 10, 2018 12:25 pm

Oh yeah indeed this is the compression used for your images :)
For sprite it's recommended to set to NONE (no compression) or FAST (fast compression) if you plan to use dynamic VRAM upload (mean it will unpack and upload tiles on the fly), for static VRAM allocation you can use BEST compression as it will be done once only.

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Tue Aug 07, 2018 1:54 am

Hello again. :)

Maybe I did not search very well, my doubt is:

Is there any code to enable/disable screen?

In BEX there is a simple code to do it.

I am trying to hide some glitches when drawing on plane A and B, when changing between screen, for example: start screen to first stage.

On emulator it is working ok when changing screens, but on mega drive some tiles remain on screen. If there is no code to do it in a simple way: I will try to set all palettes black.

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

Re: dealing with matrices (arrays)

Post by Stef » Tue Aug 07, 2018 7:33 am

You can use VDP_setEnable(..) method to quickly disabled / enabled display :)

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Thu Aug 09, 2018 12:35 am

Thanks again!

It works in part, but sometime the screen freezes at black screen.. I solved the problem when setting all the palettes black. :)

Everything is working fine.

I will upload the rom of the game soon.. just making more levels. Wait for it. :D

User avatar
Miquel
Very interested
Posts: 360
Joined: Sat Jul 30, 2016 12:33 am

Re: dealing with matrices (arrays)

Post by Miquel » Thu Aug 09, 2018 1:00 am

And what has to do disabling render with palettes? Probably you have found a bug that appears and disappears depending on the code around.

Anyway try to do a fade in since is much better visually.

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Thu Aug 09, 2018 11:26 am

Miquel wrote:
Thu Aug 09, 2018 1:00 am
And what has to do disabling render with palettes? Probably you have found a bug that appears and disappears depending on the code around.

Anyway try to do a fade in since is much better visually.
I may add a fade in. ;)

It is a really small visual problem.. some garbage tiles keeps randomly appearing on screen when transition between levels.

It happened in this old game called "I hate cars" (english translation of "odeio carros") that I made with BEX before I learnt how to disable screen. On emulator works fine, but on real hardware you can see the garbage tiles that I mention when go to other level or restart a level (pressing A).

https://youtu.be/nmXX0rMg5sA

User avatar
Miquel
Very interested
Posts: 360
Joined: Sat Jul 30, 2016 12:33 am

Re: dealing with matrices (arrays)

Post by Miquel » Sat Aug 11, 2018 12:39 am

For "stop and load" games (those that only load between levels) the following procedure is observed:
1- A "end level" condition is detected
2- Some changes to the behaviour of characters is applied to forbid the game to continue in regular conditions (like main character dead)
3- Fade in is started (SGDK has it build in, I think)
4- On fade in completed, game is completely stopped, and loading commences (level, gfx,...). You could disable render to access faster to vdp.
5- On finish loading, characters are resituated (perhaps initialized), level vars (like scroll) set and fade out is started. Game starts.

nemezes
Interested
Posts: 32
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Wed Nov 21, 2018 2:27 pm

I followed the tip of Stef to use the 64x64 screen size.

Code: Select all

VDP_setPlanSize(64, 64);

VDP_setWindowAddress(0xB000);
VDP_setSpriteListAddress(0xBC00);
VDP_setHScrollTableAddress(0xB800);
VDP_setBPlanAddress(0xC000);
VDP_setAPlanAddress(0xE000);
I do not understand about those address, but I get some trouble when using the 64x64 plan size with those address.

The problem was related with sprites: I add 4 sprites on screen, then the forth sprite didnt show.

When I erased the command line "VDP_setSpriteListAddress(0xBC00);" the 4 sprites were on screen.

I dont know if without this command "VDP_setSpriteListAddress(0xBC00);" I will get into trouble in the future. :?:

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests