Professional Documents
Culture Documents
Simple Animated Tiles in SGDK: Home Blog Games
Simple Animated Tiles in SGDK: Home Blog Games
com/)
/) Blog (https://www.ohsat.com
Home (https://www.ohsat.com
/post/)
/game/)
Games (https://www.ohsat.com
Tutorials (https://www.ohsat.c
om/tutorial/)
/staticpage/about/)
About (https://www.ohsat.com
NOTE:
This tutorial is most likely not compatible with versions of SGDK above 1.70.
Unfortunately, I
simply do not have the capacity or ability to update them right now. Read more about it here
(https://www.ohsat.com/post/about-the-sgdk-tutorials/). Sorry.
Ninja Time!
If you like 90s platformers, check out my new game Chibi Ninja Shino-kun
(https://www.ohsat.com/game/shino-kun)!
(https://www.ohsat.com/game/shino-kun)
(https://www.ohsat.com/game/shino-kun)
Animated backgrounds can add a little spice to a game’s visuals. There’s nothing like blinking city lights or rustling
trees! But while SGDK does support animated sprites, there is no real support for animated tiles. However, there
doesn’t really need to be, as animating tiles is actually very easy!
Note: This approach is simple and it works, but it can cause performance issues when you want to animate a lot of
stuff. There is a more efficient way to achieve background animations, but I will actually have to do some more
research myself before I can make a tutorial on that. So, until then, maybe this simple approach will suffice for your
use case!
Okay, so, what are animations? Actually just a series of images we flip through so quickly that our brain is
bamboozled. So, to animate background tiles, we’d just need to flip through a couple different tiles in the same
position. And yeah, it’s pretty much as easy as it sounds, especially since we have a number of ways to place tiles in
SGDK (https://www.ohsat.com/tutorial/mdmisc/placing-tiles/)!
So, if you wanted to have blinking lights in a city building for example, you’d just need one tile with the lights on and
one with the lights off. Then you’d simply load the tileset as usual, by doing
VDP_loadTileSet(mytiles.tileset,1,DMA) for example. And then you pretty much just need to know the
coordinates of the tile you want to animate, a variable to count the frames, and maybe a variable to keep track of
which tile is currently being shown. All this might look something like this:
int main()
while(1)
counter--;
if(counter == 0)
if(toggle == TRUE)
VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,2),2,2);
toggle = FALSE;
}else
VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,1),2,2);
toggle = TRUE;
counter = 60;
SYS_doVBlankProcess();
Now the tile at position 2,2 of BG_B will switch between the graphics stored in index 1 and 2 of VRAM every 60
frames (or one second), thereby creating an animation!
As you can see, this solution is very simple and kinda dumb, but hey, it works. You can also expand the code to
create animations with, for example, 3 frames:
int main()
u16 currentFrame = 0;
while(1)
counter--;
if(counter == 40)
VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,1),2,2);
VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,2),2,2);
} else if(counter == 0)
VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,3),2,2);
counter = 60;
SYS_doVBlankProcess();
The good thing about this solution is that it’s simple and rather flexible. However, as I said, it can lead to
performance issues down the line, and it can be a bit irritating having to keep track of all the frames and tile
positions throughout the game, especially when you have a huge map. There are ways of achieving animated
background tiles that mitigate these issues, and I’ll do a tutorial on them once I’ve figured out how it all works!
If you've got problems or questions, join the official SGDK Discord (https://discord.gg/xmnBWQS)! It's full of people a
lot smarter and skilled than me. Of course you're also welcome to just hang out and have fun!
No soy un robot
reCAPTCHA
Privacidad - Condiciones
(Check your spam folder if you don't get the confirmation mail)
Powered by CleverReach (https://www.cleverreach.com/?
utm_source=system&utm_medium=form&utm_campaign=c172068). I won't send you spam or sell/give your email
address to someone else. You
can unsubscribe (https://seu2.cleverreach.com/f/172068-168929/wwu/) at any time.
By clicking the subscribe button above,
you
confirm that you have read and agreed to the privacy
policy
(http://www.ohsat.com/staticpage/privacy-policy/).
(https://www.patreon.com/ohsat)
Comments
By using the Disqus service you confirm that you have read and agreed to the privacy policy
(https://www.ohsat.com/staticpage/privacy-policy).
ALSO ON OHSAT
0 Comments
1 Login
Name
Do a Sociality!
[BLK] U U F F HK (or just click an icon)
(https://twitter.com/ohsat_games)
(https://www.instagram.com/ohsat_games/)
(https://www ohsat com/staticpage/newsletter/)
(https://www.ohsat.com/staticpage/newsletter/)
(https://mastodon.gamedev.place/@and0)
(https://www.youtube.com/channel/UCN8e9XQWV5fJmHtgBg
()
(https://www.patreon.com/ohsat)
About (https://www.ohsat.com/staticpage/about/)
Newsletter (https://www.ohsat.com/staticpage/newsletter/)
Datenschutzerklärung
(https://www.ohsat.com/staticpage/datenschutz/)
Impressum (https://www.ohsat.com/staticpage/impressum/)
Privacy Policy (https://www.ohsat.com/staticpage/privacy-
policy/)
Press (https://www.ohsat.com/press)