Game Development Reference
In-Depth Information
We will go through the details of the XML file in greater detail later in the next
chapter. For the Hello World sample, we will define a game state object that we
can use to share game states among all the players within a game room. We will
name the class as HelloGameState , but you are welcome to call it by any name or
something that makes sense to your game. You may also define as many game state
classes as you like. For the HelloGameState in the schema file, each game state
instance will define three properties, namely, x, y, and color.
Code generator
In order to create the AS3 class files from the schema file, you need to run the
batch file called PulseCodeGen.bat found in the $\bin folder. It takes the
following three parameters:
1. Path to schema file.
2.
Namespace.
3.
Output directory.
In order to make our life easier, let us create a batch file that will call the
PulseCodeGen and pass all the required parameters. The reason for creating the
batch file is that you have to code generate every time you modify the schema file. As
you progress through your game implementation, it is normal to add a new class or
modify an existing one.
The convenience batch file may look like what's shown next. Let's call it init.bat
and save it in the same root folder for the sample along with the schema file.
@ECHO OFF
IF EXIST .\src\hw\gsrc\client del .\src\hw\gsrc\client\*.as
CALL "%GAMANTRA%"\bin\PulseCodeGen.bat .\GameSchema.xml hw.gsrc .\src\
hw\gsrc
IF NOT %ERRORLEVEL% == 0 GOTO ERROR
ECHO Success!
GOTO END
:ERROR
ECHO oops!
:END
pause
The schema file parameter to the Pulse code generator is specified as .\GameSchema.
xml because the schema file and the batch file are in the same folder. The second
parameter is the package name for the generated classes—in this example, it is
specified to be hw.gsrc . You specify the directory that the generated classes will be
saved to as the last parameter. Note that the code generator appends client to both
the package and directory into which it will be saved. It is also important to match
the package name and directory structure as required by the AS3 compiler.
 
Search WWH ::




Custom Search