Game Development Reference
In-Depth Information
On every frame update, the game will call the update method.
This function determines the amount of time that has elapsed
since it was last called, and then this function calls a number of
other methods.
//BEGIN GAME LOOP LOGIC
protected function update(e:Event):void {
_deltaTime = (getTimer() - _previousTime)/1000;
_previousTime = getTimer();
readKeyInput();
applyForces();
movePlayer();
moveEnemies();
checkPlayerCollisions();
render();
}
As a top-level summary, before we dig into each method indivi-
dually, here is the process that takes place in the course of an
update .
￿
The game checks to see which keys are pressed, so that it can
apply player forces if necessary.
￿
Physics forces are applied to the player.
￿
The player
s
position in the form of temporary properties ( tempX and
tempY ).
'
s cumulative forces are used to update the player
'
￿
All of the enemies in the game are moved according to their
motion parameter; they are also checked for collisions against
walls.
￿
The player is collision-checked against different kinds of Sprites,
depending on the player
'
s position in the grid; portals are not
checked, until the
use
key is pressed.
￿
If the player is colliding with a wall, the player
'
s temp position
is updated to adjust for the wall.
￿
If the player is colliding with an enemy, a death event is
dispatched.
￿
If the player is colliding with an item, the item is added to the
inventory, and an inventory update event is dispatched.
￿
The player
temporary positions are assigned to
their respective x and y values, having been correctly adjusted
for collisions.
'
sandenemies
'
protected function readKeyInput():void {
var movement:Vector3D = _config.playerMovement.clone();
movement.scaleBy(_deltaTime);
if (_keyLeftPressed) {
_player.netForce.decrementBy(movement);
}
Search Nedrilad ::




Custom Search