Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

(https://www.ohsat.

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

Simple Animated Tiles in


SGDK
Posted October 4, 2021

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)

Thank you to my excellent patron Duncan, who suggested this tutorial!

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()

//Load your tileset, set up palettes...

u16 counter = 60; //Change tile every 60 frames

bool toggle = FALSE;

while(1)

counter--;

if(counter == 0)

if(toggle == TRUE)

//Show second frame of animation

VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,2),2,2);

toggle = FALSE;

}else

//Show first frame of animation

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()

//Load your tileset, set up palettes...

u16 counter = 60;

u16 currentFrame = 0;

while(1)

counter--;

if(counter == 40)

//Show first tile after 20 frames

VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,1),2,2);

} else if(counter == 20)

//Show second tile after 40 frames

VDP_setTileMapXY(BG_B,TILE_ATTR_FULL(PAL1,0,FALSE,FALSE,2),2,2);

} else if(counter == 0)

//Show third and final tile and reset the counter

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!

Join my mailing list!


You'll get notified whenever cool stuff happens!
Email
Subscribe

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/).

Take It to the Next Level!


Become an excellent patron on Patreon (https://www.patreon.com/ohsat) and
snatch yourself some kickass perks such as early builds, exclusive updates and
more!

(https://www.patreon.com/ohsat)

Want To Buy Me a Coffee?


Coffee rules, and it keeps me going! I'll take beer too, though.

Support Me on Ko-fi (https://ko-fi.com/Y8Y0FGZ2)


Check out the rest of this tutorial
series!
Creating Graphics for the Mega Drive (https://www.ohsat.com/tutorial/mdmisc/creating-graphics-for-md/)
How to Quickly Generate C Prototype Functions in VSCode (https://www.ohsat.com/tutorial/mdmisc/c-auto-
prototype-extension/)
Color Swapping (https://www.ohsat.com/tutorial/mdmisc/colorswaps/)
4 Programs For Creating Mega Drive Graphics (https://www.ohsat.com/tutorial/mdmisc/md-graphics-software/)
Editing the Rom Header (https://www.ohsat.com/tutorial/mdmisc/rom-header/)
Simple Game States (https://www.ohsat.com/tutorial/mdmisc/simple-game-states/)
Creating a Simple Menu (https://www.ohsat.com/tutorial/mdmisc/simple-menu/)
Changing The Text Color in SGDK (https://www.ohsat.com/tutorial/mdmisc/changing-text-color-sgdk/)
Playing Music in SGDK (https://www.ohsat.com/tutorial/mdmisc/playing-music/)
Converting VGZ to VGM (https://www.ohsat.com/tutorial/mdmisc/converting-vgz-to-vgm/)
Processing Resets (https://www.ohsat.com/tutorial/mdmisc/processing-resets/)
Drawing Tiles From Code (https://www.ohsat.com/tutorial/mdmisc/drawing-from-code/)
Make a Text Crawl, Streets of Rage Style (https://www.ohsat.com/tutorial/mdmisc/sor-style-text-crawl/)
Scrolling Maps (https://www.ohsat.com/tutorial/mdmisc/scrolling-maps/)
Placing Tiles (https://www.ohsat.com/tutorial/mdmisc/placing-tiles/)
Simple Animated Tiles in SGDK
Simple Password System (https://www.ohsat.com/tutorial/mdmisc/simple-password-system/)
Checking the Region (https://www.ohsat.com/tutorial/mdmisc/region-check/)
Playing Multiple Music Tracks (https://www.ohsat.com/tutorial/mdmisc/playing-multiple-music-tracks)

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

Simple Animated Tiles Changing The Text Color Megalaga BONUS -


Megatiler 1 in SGDK in SGDK Powerup T
2 years ago • 2 comments a year ago • 5 comments 3 years ago • 4 comments 3 years ago • 12 comments 2
Welcome back to another Animate tiles in a dumb way! SGDK makes it easy to put One of the coolest things in W
Mega Drive project tutorial! text on screen, using shmups are the powerups. w
This time around we’ll create functions such as It’s fun to grab them to see i

Write like an Egyptian


0 Responses

Upvote Funny Love


Surprised Angry Sad

0 Comments 
1 Login

Start the discussion…

LOG IN WITH OR SIGN UP WITH DISQUS ?

Name

 Share Best Newest Oldest

Be the first to comment.

Subscribe Privacy Do Not Sell My Data

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)

© All rights reserved. Powered by Hugo (https://gohugo.io) and Minimal (https://github.com/calintat/minimal)

You might also like