Wednesday, February 22, 2006

Through the keyhole

What kind of person would code in a place like this? A little insight into our work holes, where we spend hours perfecting blog posts like this for you guys and then a couple of minutes on the game ;-)

Jon
Tom

Monday, February 06, 2006

Solid Geometry

Well,

Since the demo i have been working hard on ironing out the little issues we had left and adding some new 3D features into the engine.

I thought i would write my first indepth post on the technology behind the game, and explain how we are achieving 3d objects while maintaining (hopefully!) high frame rates. I am using a technique that was explained to me by kirill mourzenko several years ago, and i used a less advanced version in my earlier (unfinished) game Felony (on which Jon helped with the physics, and is actually how we hooked up for this game!)


Faking It

The 3d objects in Flash Racer are faked through a combination of clever scaling, animation and paralax scrolling. Firstly, for each object the distance is found between it and the center of the screen. For buildings, this distance is then used to offset the roof by an amount depending on the buildings height. So, as the building moves further from the center of the screen the roof becomes more offset, this creates the impression of perspective.



See how the building to the left appears to be leaning more? Of course for taller buildings this effect is even more dramatically increased. The roof of the building is also scaled up according to its height as objects closer to the camera should appear bigger!

The walls are wedge shaped images that are simply scaled to fit between the base of the building and the side of the roof, at the moment this calculation is performed every frame in the Camera Class, however this could be reduced for lower spec machines and i am looking into making this one of the many graphics options we are likly to include!


The final piece of the puzzle is to skew the wall image so that it fits when the roof is no longer above the building base. This is predone animation, with one keyframe for every single pixel of movement (81 keyframes in total), this is a very efficient way of achieveing the right look.







On a side note, i have noticed that you can now dynamically skew images in flash 8, this would have been ideal for this, however we are currently coding for flash player 6 in AS1 so it would be unreasonable to code only one feature in the brand new flash player! Maybe in a future version?


Pseudo Speed

These tall objects are great, because they add that extra level of depth to the game and just as importantly - because they are closer to the camera, they move faster and dramatically increase the feel of speed when racing! All we need now is a little blurring...

Any questions? Just leave a comment! Extra points if you can work out the cryptic title ;-)