Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Working with sprites and make animation

Reply to topic
Author Message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Working with sprites and make animation
Post Posted: Thu Jun 13, 2019 12:19 am
Some days ago I started to study DevkitSMS development and I did not understand how I should proceed to leave the sprites with transparent background and how to animate them. I would appreciate the help of the forum members.

Thank you very much in advance.
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 886
  • Location: Spain
Reply with quote
Post Posted: Thu Jun 13, 2019 6:23 am
The first color (0) of the sprite palette would be considered transparent on a sprite (automatically). Regarding animation, there's no built in sprite animation system, you have to build it by yourself.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Jun 13, 2019 2:31 pm
as said, any pixel that's using color 0 on a sprite will be transparent.

as for the animations, there are two options which are basically:

- animate a sprite by pre-loading the animation tiles in VRAM and using them in different frames: for instance, say you load your animation's 4 frames into tiles 7,8,9 and 10. If you'll use tile 7, later you'll use tile 8 and then 9 and finally 10 (if you change that each frame you'll have your animation running at 50 or 60 fps, according to your system's TV standard, so you probably want to show the same tile more than once...)

- animate a sprite by reloading contents in the tile according to the frame you need. So if your sprite is using tile 23, for instance, you can change the contents of tile 23 (during vblank, likely!) when it's time to show the next image
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14740
  • Location: London
Reply with quote
Post Posted: Thu Jun 13, 2019 3:58 pm
One of the things I'd like to see in homebrew is 60fps sprite (and tile) animation... but that is probably rather onerous for the artist.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Jun 13, 2019 4:15 pm
IMHO everything over 20 fps is totally useless.
But to prove I'm wrong you can code a small 3D spinning wireframe cube rendered into some 16 tiles in screen center and see if updating it at each frame makes any difference to -say- each other frame ;)
  View user's profile Send private message Visit poster's website
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
color 0 em palette
Post Posted: Thu Jun 13, 2019 6:13 pm
kusfo wrote
The first color (0) of the sprite palette would be considered transparent on a sprite (automatically). Regarding animation, there's no built in sprite animation system, you have to build it by yourself.



What I do not understand, so I understand the color 0 in my palette
cats.jpg (34.28 KB)
cats.jpg

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Thu Jun 13, 2019 7:45 pm
the color 0 meaning the first element in your palette, as in my_array[0]

you're likely going to prepare your sprites over a key color background, such as magenta, like this for example:

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTFgzfONPdqgU4ip56oAAXpf7Ko...

and then save your image to PNG (or some other format for indexed images) ensuring that your magenta gets color index 0.

Then you use Maxim's BMP2Tile to turn your image to tiles.
C278AC81-C34F-4C3D-B094-535A2BE80B01.png (9.64 KB)
Attachment fairy
C278AC81-C34F-4C3D-B094-535A2BE80B01.png

  View user's profile Send private message Visit poster's website
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
All Right !
Post Posted: Fri Jun 14, 2019 3:26 pm
PsychoMaster wrote
Some days ago I started to study DevkitSMS development and I did not understand how I should proceed to leave the sprites with transparent background and how to animate them. I would appreciate the help of the forum members.

Thank you very much in advance.


Thanks !!
  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
I can not display background image correctly
Post Posted: Fri Jun 14, 2019 3:31 pm
PsychoMaster wrote
Some days ago I started to study DevkitSMS development and I did not understand how I should proceed to leave the sprites with transparent background and how to animate them. I would appreciate the help of the forum members.

Thank you very much in advance.



I do not understand why not trying to put this background image for the scenario I get this result.
cats.jpg (280.87 KB)
cats.jpg

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Jun 14, 2019 3:51 pm
Please explain your steps.
Have you got a 256x192 pixel image you converted to tiles, tilemaps and palette in BMP2Tile?
Are you sure you're loading them correctly? It seems the tilemap isn't good...
  View user's profile Send private message Visit poster's website
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Post Posted: Fri Jun 14, 2019 3:57 pm
Last edited by IllusionOfMana on Fri Jun 14, 2019 3:59 pm; edited 1 time in total
Quote
I do not understand why not trying to put this background image for the scenario I get this result.


are you loading your tiles into the appropriate vram location and are you loading the sprite table correctly?

lastly are you loading your palette information correctly as well.

will provide some examples of a bad load and a good load (sorry for camera shots, took these off my IG)
badload.PNG (562.13 KB)
bad tile and palette load
badload.PNG
goodload.PNG (580.93 KB)
good tile and palette load
goodload.PNG

  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Post Posted: Fri Jun 14, 2019 3:58 pm
sverx wrote
Please explain your steps.
Have you got a 256x192 pixel image you converted to tiles, tilemaps and palette in BMP2Tile?
Are you sure you're loading them correctly? It seems the tilemap isn't good...




Yes, the map was created using bmp2tile, the size of 256X192

My code:

SMS_loadBGPalette(stage_palette__bin);
SMS_loadPSGaidencompressedTiles(stage_psgcompr, 0);
SMS_loadTileMapArea(0, 0,stage_bin, 32, 24);
SMS_displayOn();
  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Post Posted: Fri Jun 14, 2019 5:10 pm
PsychoMaster wrote
sverx wrote
Please explain your steps.
Have you got a 256x192 pixel image you converted to tiles, tilemaps and palette in BMP2Tile?
Are you sure you're loading them correctly? It seems the tilemap isn't good...




Yes, the map was created using bmp2tile, the size of 256X192

My code:

SMS_loadBGPalette(stage_palette__bin);
SMS_loadPSGaidencompressedTiles(stage_psgcompr, 0);
SMS_loadTileMapArea(0, 0,stage_bin, 32, 24);
SMS_displayOn();



Hello again ! I am grateful for everyone's attention.
I was able to display correctly using another map, but when I add my sprites it stays that way as in the image.
cats.jpg (282.35 KB)
cats.jpg

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Fri Jun 14, 2019 5:17 pm
Background and sprites are both made of tiles - you're placing your sprites' tiles in video memory (VRAM) somewhere over your background tiles...
  View user's profile Send private message Visit poster's website
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Thanks !!!
Post Posted: Fri Jun 14, 2019 9:47 pm
sverx wrote
Background and sprites are both made of tiles - you're placing your sprites' tiles in video memory (VRAM) somewhere over your background tiles...


I undestand !
Thank you very much !!
  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
yet error in image
Post Posted: Sun Jun 16, 2019 2:38 am
sverx wrote
Background and sprites are both made of tiles - you're placing your sprites' tiles in video memory (VRAM) somewhere over your background tiles...



I thought you understood the cause, but even with just the image alone, if sprites appear that way. I did a test with the Phantasy Star title screen and it is displayed correctly, I use the bmp2tile for the image I want to use, but most present this problem.
Using SMS_loadTileMapArea or SMS_loadTileMap.
cats.jpg (187.28 KB)
cats.jpg

  View user's profile Send private message
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Post Posted: Sun Jun 16, 2019 3:51 am
It looks like you ran out of vram. The image youre trying to render uses a lot of similar tiles that are just flipped. try optimizing your tile map and the tile set being loaded in. This may also be causing the odd palette issue as well... (unless those were your intended colors...)
  View user's profile Send private message
  • Joined: 29 Mar 2012
  • Posts: 886
  • Location: Spain
Reply with quote
Post Posted: Sun Jun 16, 2019 4:11 pm
sverx wrote


you're likely going to prepare your sprites over a key color background, such as magenta, like this for example:

https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTFgzfONPdqgU4ip56oAAXpf7Ko...


A bit of offtopic but, where're this graphics from? I like them!
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Jun 17, 2019 8:50 am
PsychoMaster wrote
I thought you understood the cause, but even with just the image alone, if sprites appear that way. I did a test with the Phantasy Star title screen and it is displayed correctly, I use the bmp2tile for the image I want to use, but most present this problem.
Using SMS_loadTileMapArea or SMS_loadTileMap.


As IllusionOfMana suggested, you're probably using too many tiles. You can expect to be safe as long as your total number of tiles (background and sprites) is at most 448. Try with a simpler background.

@kusfo no idea, I just googled 'sprite sheet magenta'.
  View user's profile Send private message Visit poster's website
  • Joined: 29 Mar 2012
  • Posts: 886
  • Location: Spain
Reply with quote
Post Posted: Mon Jun 17, 2019 10:03 am
I'll do a reverse searching to find it xD
  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Post Posted: Mon Jun 17, 2019 2:30 pm
sverx wrote
PsychoMaster wrote
I thought you understood the cause, but even with just the image alone, if sprites appear that way. I did a test with the Phantasy Star title screen and it is displayed correctly, I use the bmp2tile for the image I want to use, but most present this problem.
Using SMS_loadTileMapArea or SMS_loadTileMap.


As IllusionOfMana suggested, you're probably using too many tiles. You can expect to be safe as long as your total number of tiles (background and sprites) is at most 448. Try with a simpler background.

Thanks !!

@kusfo no idea, I just googled 'sprite sheet magenta'.
  View user's profile Send private message
  • Joined: 13 Jun 2019
  • Posts: 24
Reply with quote
Tiles and Sprites
Post Posted: Mon Jun 17, 2019 7:10 pm
PsychoMaster wrote
Some days ago I started to study DevkitSMS development and I did not understand how I should proceed to leave the sprites with transparent background and how to animate them. I would appreciate the help of the forum members.

Thank you very much in advance.




What would be the best way to work with tiles to do the sprites? I've felt a lot of difficulty in this part, maybe I'm wrong or more complicated.
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14740
  • Location: London
Reply with quote
Post Posted: Mon Jun 17, 2019 8:04 pm
Draw your sprites as an image. Convert to tile data (8x8 tiles). Make your code draw the tiles for each sprite, using the correct tile numbers, at correctly spaced x, y coordinates. How you achieve that depends a lot on how you are animating things and how you need to deal with sprites in your game.

If you have a static set of sprites which stay on screen then you can just set things up once and then just update the coordinates; if it's more complicated then you need something complicated to deal with it, like dynamically generating the sprite table on each frame based on what's visible.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Jun 18, 2019 12:14 pm
PsychoMaster wrote
What would be the best way to work with tiles to do the sprites? I've felt a lot of difficulty in this part, maybe I'm wrong or more complicated.


Build a (or a few) sprite sheet(s). If your sprites are 16 pixel tall, use the designated BMP2Tile option ("Treat as 8x16") when saving the tiles.
Remember that you can use only tiles in either the first or the second half of VRAM for sprites.
Once you've loaded your tiles in VRAM, refer to them by their tile number when adding sprites. I usually have a bunch of #defines for that...
  View user's profile Send private message Visit poster's website
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Post Posted: Tue Jun 18, 2019 2:15 pm
working with tiles and sprites can be complicated.
Tiles
I found it was draw 8x8 pixel tiles in any paint program then load them into a map builder called Tiled then export that map as a PNG or BMP image. I then use UGT which is bundled with Psidum's GSLib or ill use bmp2tile. both these programs will allow you to optimize your tile set as well as export a tileset, tile map, and palette.
Sprites
Similar steps as the first, draw 8x8 pixel tiles for your sprite in your preferred paint program and export it at a PNG or BMP. This time using bmp2tile and turning off any optimization options and exporting both the tileset and palette.
Programming
Within your program you need to be mindful of your VRAM. I believe you get some 512 entries or 256 enteries per palette.
thats 256 8x8 pixel tiles and 256 8x8 pixel sprites (however due to the SAT and Screen Buffer taking up memory, the sprite section doesnt actually have 256 entries available to it but instead around 190 tiles).
So be mindful on how many tiles and sprites youre loading into VRAM or you will overflow and cause graphical glitches and other issues. You also only have 64 entries into to Sprite Table despite the sprite section of VRAM allowing more than double that.
So to recap, you get:
256 tiles
190 sprites
2 color palettes of 16/64 colors (for sprites, color zero is the cutout mask)
64 max on screen sprites

I'll provide some examples below of how some of the things Ive set up look.
One of them is a snapshot within an emulator and will show you exactly how your VRAM should look with sprites and tiles separated per section.
Spriteset.png (14.95 KB)
Spriteset
Spriteset.png
output-04.png (9.13 KB)
In Game Screenshot
output-04.png
thecourtyard.PNG (104.58 KB)
Tilemap
thecourtyard.PNG
ih8tthesmspal.PNG (64.34 KB)
Tileset (color SMS to fullRGB)
ih8tthesmspal.PNG
output-01.png (38.13 KB)
In Emu Snap
output-01.png

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3827
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Jun 18, 2019 3:13 pm
IllusionOfMana wrote
I believe you get some 512 entries or 256 enteries per palette. That's 256 8x8 pixel tiles and 256 8x8 pixel sprites (however due to the SAT and Screen Buffer taking up memory, the sprite section doesnt actually have 256 entries available to it but instead around 190 tiles).


More precisely: you safely got 448 tiles (tiles from 0 to 447) to use, but you need to share this space for both sprites tiles and background tiles.
As sprite tiles should be either in the first half or in the second half of VRAM, you can have up to 256 tiles for sprites if you use the first half of VRAM but only 192 tiles for sprites if you use the second half (devkitSMS default).
For the background you can use all the remaining tiles. So if you're using very few tiles for sprites, you can use more tiles in your background.

@IllusionOfMana - that's looking great! :)
  View user's profile Send private message Visit poster's website
  • Joined: 08 Sep 2018
  • Posts: 270
Reply with quote
Post Posted: Tue Jun 18, 2019 4:12 pm
sverx wrote

More precisely: you safely got 448 tiles (tiles from 0 to 447) to use, but you need to share this space for both sprites tiles and background tiles.
As sprite tiles should be either in the first half or in the second half of VRAM, you can have up to 256 tiles for sprites if you use the first half of VRAM but only 192 tiles for sprites if you use the second half (devkitSMS default).
For the background you can use all the remaining tiles. So if you're using very few tiles for sprites, you can use more tiles in your background.

@IllusionOfMana - that's looking great! :)


Right, I was more or less keeping it simple as thats what I did for mine. I omitted a good 2 or 3 tiles between the last half and the screen buffer since he seems to be having a lot of issues with writing into the screen buffer. He also seems to be overwriting the second half of VRAM a lot too...

Also thanks, that project is almost finished! Talked to Psidum earlier, he's reworking GSLib quite a bit so I'm hoping his next update will help fix some of my enemy sprite issues with the on screen check.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!