Using PHPObject to Save and Retrieve Simple Game Levels
[ May 27, 2004 ] by Tor de Vries
Using a simple video game level editor in Flash as a foundation, this whitepaper/tutorial explains how to use ActionScript, PHP, and the PHPObject "Flash remoting" libraries to save and retrieve data to/from a server in XML format.


Contents:

» Introduction
» Getting Started
» The Concepts of PHPObject
» How Leditor Works
» Comments & Resources

Introduction

Video games are frequently tile-based. A “tile-based” game uses a library of preset graphical objects to display the game’s interface. One tile might contain graphics for a patch of grass, while another could illustrate a square of cement sidewalk. Tiles are designed to seamlessly mesh with surrounding tiles, so that a large and varied gamespace can be created from a handful of tiles. Popular games like SimCity and Warcraft are good examples, though most side-scrollers and first-person-shooters are also usually tiled. Tile-based games also lend themselves to level editors, graphical interfaces that allow game designers to place game elements on an actual level, rather than trying to create the level arrays with hand-typed text. This also allows players to create their own levels. These levels need to be saved somewhere for designers to retrieve and edit.

This whitepaper introduces a simple game level editor in Flash, using Ghostwire's free PHPObject libraries to do "Flash remoting" to save and retrieve data to/from a server. The official definition of Flash remoting is that it enables "a powerful yet simple programming model and runtime enabling Macromedia Flash MX to connect to remote services exposed by application servers and web services". In other words, Flash can now talk to your server without having to encode and decode variables through loadVariables() or XML.sendAndLoad(); your ActionScript and your server-side language can simply refer to the same sets of objects. Specifically, PHPObject allows Flash and PHP to share the same object class as if it was native to the code.

You can play with this level editor on my web site. It is not for a particular game, but serves as a good vehicle for explaining Flash remoting. In this level editor, there are seven possible tile shapes:

These represent open space, treasure, obstacles, walls and the player. The level editor provides a grid of tiles, 20 on each side, for a total of 400 tiles. After choosing a shape from the toolbox, you can click on individual tiles to change them to that shape. You could end up with a level like this:

This level could then be read into a game engine and rendered onscreen as a birds-eye game (like Pac-man), an isometric game (like Warcraft) or something else, using far more detailed tiles than those represented in the editor.


 
 
 
Name: Tor de Vries
Location: New York
Age: 30
Flash experience: I first began toying with it back when it was called "FutureSplash" and wasn't owned by Macromedia, if anyone else remembers that. Since then it has been a favorite tool alongside DHTML, JavaScript, PHP, Perl, XML and other buzzwords.
Job: Digital Designer
Website: http://www.tordevries.com/
 
 
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| www.smartfoxserver.com | www.gotoandplay.biz | www.openspace-engine.com |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048