Game on Arduino using 2.8" TFT Shield

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Rikonator
 
Posts: 2
Joined: Sat May 12, 2012 5:23 am

Game on Arduino using 2.8" TFT Shield

Post by Rikonator »

I want to make a side-scrolling game, kind of like a Super Mario Bros clone, to work on the Arduino using the 2.8" TFT Shield(http://www.adafruit.com/products/376). This is my first Arduino project, and I know that it is pretty complicated given that it is my first project. My cousin donated his 2.8" TFT Shield so I wanted to use it.

I'm using an Arduino Duemilanove with the Atmega328. Basically, I'm reading bitmaps from the SD card and rendering them onto the screen accordingly.

A few weeks into the project, I realized that the time required to render a bitmap onto the screen was too large. This contributes to the game running at 1 frame per 3-5 seconds. So now I'm trying to optimize how I write data to the screen. But I can't figure out how to.

The writeData() function in the TFTLCD library already uses direct port access. I do not know if trying to convert that code to avr-assembly will help or not. Also, I lack the knowledge on what are the proper pin accesses each write uses to write the data.

Can anyone help me optimize the rendering? Any documentation I can read to understand how to get a better FPS? Or is it already optimized, and I can't do anything about it?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Game on Arduino using 2.8" TFT Shield

Post by adafruit_support_rick »

Are you reading your bitmaps from the SD card in real time? That is, are you trying to read a frame, then render it on-screen, then read the next frame, etc? If so, a rate of 0.3 fps is probably about as good as you can do.

You might want to have a look at the Gameduino shield that adafruit sells:
http://www.adafruit.com/products/384
also, check out the Gameduino page to get some idea of how games are constructed to get high frame rates.
http://excamera.com/sphinx/gameduino/

Good luck!

Rikonator
 
Posts: 2
Joined: Sat May 12, 2012 5:23 am

Re: Game on Arduino using 2.8" TFT Shield

Post by Rikonator »

That's what I thought, too. But I was hoping that I could somehow speed up the process of sending data to the GRAM or even speed up the process of reading data from the SD card.

I don't want to invest in a Gameduino before making sure this approach will not work.

The size of the bitmap does not allow me to use PROGMEM. I need a lot more than the 32KB offered by the Duemilanove. So using the SD card is my best bet. Is there anyway I can improve the rendering process (which does involve reading from the SD card and then writing the data to the screen, per pixel)?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Game on Arduino using 2.8" TFT Shield

Post by adafruit_support_rick »

Hmmm. I'm still not entirely sure I understand your approach to this exactly. I get the idea that you have each individual frame stored on the SD card, and so for each frame, you are reading an entire 240x320 color .bmp and completely rewriting the screen. Is that true?

If so, that just isn't likely to work. You might be able to squeeze a few extra milliseconds out of the SD driver and a few more out of the graphics library, but you're at about 1/4 fps and you need to be closer to 20fps. That's an 80:1 speedup - wayyyyy more than you'd get by just shaving a few ms per frame.

To get there, you're going to have to change your approach to this. Instead of redrawing the entire screen, you're going to have to figure out how to redraw only those areas of the screen that have changed.

For example, imagine you want to animate a 32X32 square, bouncing back and forth between the left and right edges of the screen. You wouldn't keep redrawing the entire screen. Instead, you would draw a box-colored line at the leading edge of the box, and a background-colored line at the trailing edge of the box. Instead of writing 320X240=76,800 pixels, you're only writing, say, 1x32 pixels for the leading edge and 1X32 pixels for the trailing edge - 64 pixels total. That will go 1,200 times faster, yet it will look exactly the same.

Look at some old 8-bit nintendo or atari side-scrollers. Or old PC games. Their hardware was slower than yours, but they made up for it with clever programming. Pay attention to how they actually draw things on the screen, and see if you can figure out some of their tricks.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”