Using PHPObject to Save and Retrieve Simple Game Levels
Author: Tor de Vries (graduate student at Parsons School of Design, MFA in Design & Technology)
Keywords: Macromedia Flash, ActionScript, PHP, Flash Remoting, PHPObject, XML, server interaction, video game design, tile-based games
Summary: 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
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.
| Next Page | 1 · 2 · 3 · 4 · 5 |
The explanations and code available on this page are copyright ©2004 Tor de Vries.