Game Development Reference
In-Depth Information
Scene Editor and Script Editor
Generally, a game creation tool allows drawing or importing sprites, then generating prefabricated objects, or
“prefabs,” that use those sprites. Behavior-modifying scripts can also be added to the prefabs. When placed in a scene,
those prefabs become unique game objects. For your simplified prototyping tool, colored circles take the place of
objects and each object has exactly one script. The first step in creating a scene editor is to add a couple of classes that
represent a game object, as shown in Listings 12-3 and 12-4.
Listing 12-3. GPTEditorGameObject Class
public class GPTEditorGameObject
{
private static int NEXT_ID = 0;
public static final int DEFAULT_COLOR = Color.WHITE;
private static final String DEFAULT_SCRIPT =
"" + "\n" +
"void OnUpdate(float deltaTime)" + "\n" +
"{" + "\n" +
" " + "\n" +
"}" + "\n" +
"" + "\n";
public int id;
public float x;
public float y;
public int color;
public String script = DEFAULT_SCRIPT;
GPTEditorGameObject(float objX, float objY, int objColor)
{
id = NEXT_ID++; // assign unique ID to game object
x = objX;
y = objY;
color = objColor;
}
}
Listing 12-4. GPTGameObject Class
public class GPTGameObject
{
public int id;
public float x;
public float y;
public int color;
GPTGameObject
(int objId, float objX, float objY, int objColor)
{
id = objId;
x = objX;
y = objY;
color = objColor;
}
}
 
Search WWH ::




Custom Search