dealing with matrices (arrays)

SGDK only sub forum

Moderator: Stef

nemezes
Interested
Posts: 19
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: 19
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: 2757
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: 19
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: 2757
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: 19
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: 19
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: 2757
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.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests