Game Development Reference
In-Depth Information
will call a method named createProjectile . We will look at this method
shortly. The function that runs every frame, frameScript ,performs
three tasks. It moves the player, moves all of the projectiles, and
updates the position of the foreground and background tiles.
protected function movePlayer():void {
player.x = mouseX;
player.y = mouseY;
if (mouseX > 0 && mouseX < _stageWidth && mouseY > 0 &&
mouseY < _stageHeight) {
} else;
protected function moveProjectiles():void {
for each (var projectile:Projectile in _projectileList) {
projectile.x += projectile.speed;
if (projectile.x - projectile.width
_stageWidth) {
s x and y positions are
updated to match with those of the mouse. In addition, we check to
make sure the mouse cursor is within the bounds of the stage. If it
is, we hide the cursor so it does not cover up the player; otherwise,
we show it. The moveProjectiles method iterates through the list of
projectiles and updates each according to its speed. If the projectile
has moved too far off the screen, it is removed.
In the movePlayer function, the player
protected function moveForeground():void {
foreground.x -= _speed;
var right:int = foreground.getRect(this).right;
if (right < = _stageWidth) {
foreground.x = right - _stageWidth;
protected function moveBackground():void {
background.x -= _speed/3;
var right:int = background.getRect(this).right;
if (right
= _stageWidth) {
background.x = right - _stageWidth;
These two functions are almost identical. The only real difference
is that the background moves at one-third the rate of the
Search Nedrilad ::

Custom Search