Saturday, 18 April 2009

A Serving of SmartFox

Last night I dived into the world of SmartFox server. I've always wanted to use a socket server for a Flash game and about 5 years ago I managed to make a simple 2 player, turn-based game with a nice guy over at the FlashKit forums called random10122. Anyway, we played it a few times and it was fun but it was built without any rooms or lobby areas so users would of had to have ran the server on thier own machines thus it was never a viable project. Today, however, we have quite a few options; SmartFox, Union, ElectroServer and others. These servers are much more complete than the one that our old game was built on and since my tile game will be built with a multi-user system in mind I started looking at the different APIs. A friend of mine is currently working on a game built on SmartFox server, so his advice weighs out the differences in the APIs and I'm going forward with SFS.

This might seem like I'm going off track from tile engines, but bare with me. The main point of this topic getting introduced here is that I needed to identify the separation between the engine and the control system and also identify where they may cross over. This has a lot of bearing on many factors especially the collision detection and if multiple sprites can be controlled from various locations with PCs of various performances and latency thrown in for good measure then the earlier I think about this the better.

I'm going to start with the PC speeds issue. If over in the Venezuelan capital, Caracus, some kid is playing on their 500MHz Celeron ( jealous friends ) and some MIT computer science guru on his 80 core IBM super computer both decide to play my game at the same time, will there be a difference in frame rate? Yes.

What I need to do is make the sprites reposition based on the time that has passed between the renderings rather than using an Event.ENTER_FRAME event. This will have 2 positive impacts on the game, firstly, we can now make the game update the graphics as fast as the machine will allow us too and of course it will fix the PC performance issue.

So, If our sprite is to move 10 pixels per second in a straight line and our computer is updating the screen every 200ms, we can safely say that 1000 ms / 200 ms = 5 updates in that 1 second duration. Now we can now move our sprite by 10 pixels / 5 updates = 2 pixels per update. This is termed time-based animation and will be at the heart of my tile engine and will be my first project to fully incorporate this style of rendering graphics.

Gary Paluk

0 comments:

Post a Comment