Game Development Reference
In-Depth Information
public function getGridReference(x:int, y:int):
GridReference {
if (x < 0||y < 0) return null;
if (x > = _width || y > = _height) return null;
return _grid[x][y];
}
public function clear():void {
for (var i:int = 0; i < _grid.length; i++) {
for each (var gridReference:
GridReference in _grid[i]) {
gridReference.clear();
}
_grid[i] = null;
}
_grid = null;
}
}
}
When a new CollisionGrid object is created, it needs a width
and height. It constructs all the necessary containers and fills them
with empty GridReference objects. Because the structure and
dimensions of a level can
t change on the fly, the vector containers
have a fixed length. This improves speed and memory usage.
Getting at a specific GridReference object is as simple as calling
the getGridReference method and passing it x and y values. If a grid
square outside the range of the grid is requested, the method
returns null. Like a GridReference object, the grid also has a clear
method, which performs cleanup and disposal of all the objects.
'
The PlatformerEngine Class
Now, we
ve reached the heart of the entire game. This class is very
large (500+ lines), so I will break it up into discrete pieces. The
class is divided logically into different sets of tasks, so it
'
'
seasierto
find what you
'
re looking for. These tasks are as follows:
￿
Level XML load handling
￿
Asset load handling
￿
Level creation
￿
'
Game loop functionality (what
s run every frame)
￿
Helper methods
￿
Input handlers
This largely maps to the order of events that occur when using
the engine as well, so it is straightforward to follow. This class also
uses a ton of imports, which I
ll skip here in the text, but you can
find in the source files for this chapter. We
'
'
ll start by looking at all
the properties defined in the class.
Search Nedrilad ::




Custom Search