Thursday, 27 September 2007

J2ME Mode 7 Floor Renderer

Following on from yesterday's fixed point maths routines, here's a little demo which builds on that. It's another oldie, again from around 2002/3, which I've used in a more advanced form on quite a few projects. It's a very simple texture mapper, visually in the style of the SNES's famed mode 7. Given a 2D map, it presents the image as a horizontal texture mapped surface. It's primitive stuff but can be used to quite nice effect, and with it being entirely software based it doesn't require any additional APIs on the phone.

Grab the source and take a look at Renderer.java. Most of the work is done in renderFloor(), which simply works out a pixel offset for each scanline and fills the buffer accordingly. I've taken out some of the optimisations so it's easier to read, but even still it's no slouch!

9 comments:

dawmat said...

Great floor renderer. Does it work fast enough also on the slowest phones?

Carl Woffenden said...

Hi! It works with a decent framerate on the oldest of phones (even real dinosaurs like Nokia's 7210). Older Motorola and other slow phones usually have to draw four pixels at a time. But all in all, most phones from the past 4-5 years will run fast enough.

dawmat said...

Thanks, it's nice to know it runs well even on older phones. I might want to use it in one of my games, it looks very good.

no_es_distinto said...

Hi,

Me again ;)
Your floor mapping routine is just beautiful. It's simple, fast and because you're keeping the coordinates between 128 << fp + tile_w_bits, you can display a large terrain.
Man, you're awesome! I envy you! =)

Anyway, after several days playing with the code I couldn't be able to get the 2D position of a 3D vector.

I mean, if you've a car at 64x64x2 (x,y,z) how do you know where it should be positioned on the screen?

I've no problems with the x and y but the z is giving me headaches!

Any help or tip would be appreciated and again...

Keep doing this good stuff! =)

Carl Woffenden said...

Hi again! If you like this floor map routine, check out this one! It uses optimised version of this snippet, but with code to set the sprite positions - the comments in TrackRendererMode7.java describe how the calculations work.

no_es_distinto said...

Thanks Carl!

Iván Rodolfo said...

Hi Carl. Awesome work man, thanks for sharing.

Carl, I wanna ask you something. I'm kind of new at mobile game development, and I'm trying to do a racing game like old Kemco's Top Gear (SNES) but I can't get it done. Maybe I'm wrong but I think TG uses a different technique from Mode 7. Do you know this technique and where can I find some documentation about it? I really wanna know how to make that kind of games.

Thanks again and sorry for bothering you.

Carl Woffenden said...

Hi! The graphics in Top Gear don't look to be Mode-7, but something much simpler (and I've never looked into that style). I can't be of help there, sorry!

Iván Rodolfo said...

Thanks Carl, then I'll have to keep looking. Again, awesome work here! Thanks for sharing!