Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

SGDK only sub forum

Moderator: Stef

Post Reply
masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by masteries » Wed Apr 19, 2023 4:22 pm

Greetings,

Here we come with a very specific, but VRAM saving need

We have some tiles to be used as HUD elements for a dual player game,
these tiles consist in 4 icons and numbers from 0 to 9

As HUD elements on screen we desire:

-A sprite that represents the number of lives and number of special weapon uses,
composed of icon number 1 (its a 8x8 tile) and followed by one of the number tiles.
Followed by an icon that represents the special weapon, and last another of
the number tiles.

-Next, will be another sprite that starts with an icon that represents ammunition,
followed by 3 tiles of numbers.

-At last, another sprite (or 2 sprites) that comprises up to 8 numbers,
that is the score for player 1


-The same HUD representation will be double if second player is active,



The idea is to use only 14 tiles of VRAM, we are very limited in VRAM space
for our game.

It is easy to detect that many of the number tiles can appear multiple times,
we can´t use the standard way to load and use animated sprites, due to
our HUD tiles can be loaded once, and we only have 14 tiles of space for
entire HUD.

We assume, we need a way to manually compose sprite data, and
manage what tiles are being displayed at each sprite tile location.

But, how to perform this using SGDK?


Thanks in advance for your help,

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

Re: Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by Stef » Fri Apr 21, 2023 9:51 am

SGDK does allow to define manually where are the tiles to use for sprites by using the following function :

Code: Select all

SPR_setVRAMTileIndex(sprite, tileIndex);
You can use a dummy spriteDefinition with a single 8x8 sprite or 16x8 depending the sprite size you need so you create the sprites using these spriteDefinition, then later you use the SPR_setVRamTileIndex(..) function. You also need to disable the automatic tile upload using SPR_setAutoTileUpload(..) as you will use preloaded tiles.

Hope you sort it out :)

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by masteries » Fri Apr 21, 2023 8:57 pm

Stef wrote:
Fri Apr 21, 2023 9:51 am
SGDK does allow to define manually where are the tiles to use for sprites by using the following function :

Code: Select all

SPR_setVRAMTileIndex(sprite, tileIndex);
You can use a dummy spriteDefinition with a single 8x8 sprite or 16x8 depending the sprite size you need so you create the sprites using these spriteDefinition, then later you use the SPR_setVRamTileIndex(..) function. You also need to disable the automatic tile upload using SPR_setAutoTileUpload(..) as you will use preloaded tiles.

Hope you sort it out :)
Thanks for the answer,

But our needs are more specific,
we need to set each tile of the sprite,
as far we tested, "setVRamTileIndex"
is useful when the sprite tiles are placed together


Such example,

=>Imagine that HUD tiles are being loaded at position 2033 (in tiles) of VRAM, up to 14 tiles

=> The first sprite is composed of 4 tiles,
a sprite of 32 pixels horizontal and 8 pixels vertical (4 tiles)

=>The first tile of the sprite is the tile located at VRAM position 2047, the next tile of the sprite is the tile located at position 2035

=>Next tiles of the sprite are the tiles located at VRAM position 2046 and 2043 respectively

The tiles of the sprite, using tile numbers 2035 and 2043 can change, due to these represent numbers: life and special weapon remaining uses.


As you can see, the tiles that compose each sprite are placed elsewhere in the VRAM


These HUD tiles can't be placed in planes A or B, due to these planes are being used and scrolled. Sprites are needed, but optimized usage is needed to minimize the amount of sprites dedicated for HUD displaying.


Now, thanks to the provided example, our needs can be understood better,




As well, if this can't be done due to sprite tiles need to be read sequentially by the VDP,


How can we make usage of sprite multiplexing?

The first 20 sprites are player bullets, created and never removed. And the first 8 vertical pixels are used for HUD, map and sprites are clipped (HUD area is displayed over all). These bullet intended sprites can be used for HUD elements, and after these first 8 scanlines, switched to be used for player bullets.

But we have no idea, again :) , about how to make sprite multiplexing using SGDK, (we used sprite multiplexing for other machines)

Thanks in advance,

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

Re: Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by Stef » Wed Apr 26, 2023 8:32 pm

Indeed this is impossible to do it like that as sprite tiles need to be contiguous in VRAM. you need to split your sprite in small 8x8 pixels sprite if you want to use not contiguous tiles.

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by masteries » Thu Apr 27, 2023 5:27 pm

Stef wrote:
Wed Apr 26, 2023 8:32 pm
Indeed this is impossible to do it like that as sprite tiles need to be contiguous in VRAM. you need to split your sprite in small 8x8 pixels sprite if you want to use not contiguous tiles.
Ok, as I supposed in the post:

"As well, if this can't be done due to sprite tiles need to be read sequentially by the VDP,


How can we make usage of sprite multiplexing?

The first 20 sprites are player bullets (8x8 pixel sprites), created and never removed. And the first 8 vertical pixels are used for HUD, map and sprites are clipped (HUD area is displayed over all). These bullet intended sprites can be used for HUD elements, and after these first 8 scanlines, switched to be used for player bullets.

But we have no idea, again :) , about how to make sprite multiplexing using SGDK, (we used sprite multiplexing for other machines)"



Now, sprite multiplexing is our hope, we need to reuse player bullets as HUD sprites.

Are there sprite multiplexing guidelines?

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

Re: Custom sprites - Manual sprite composition/tile location management - intended for HUD elements area

Post by Stef » Thu Apr 27, 2023 10:05 pm

SGDK does not provide any direct support for sprite multiplexing but it is still possible using the legacy sprite engine (can be enabled through config.h file in last SGDK).
The thing is that using sprite multiplexing is tricky as you explicitly need to rewrite the sprite table during display using the h-interrupt callback for that.
I never experimented it myself but some people in SGDK discord server did so definitely possible :

https://twitter.com/birt_shannon/status ... 3192584194

Post Reply