Game Development Reference
In-Depth Information
the player. You can follow this example using the SimpleShooter.
fla file in the Chapter 6 examples folder. When exported, this
example will create an environment with a two-tiered background
that scrolls at different rates, a ship that moves with the mouse
cursor and fires the projectiles when the mouse button is clicked.
There are just two classes for this example, and We
ll look at the latter one first because it
The Projectile Class
The class controlling the projectiles fired in the game only has
one main property
its speed. Arguably, for this example, we
a single file. However, if a more advanced feature set were added
to this game, it would need classes to control each of the objects
in play, so going ahead and creating a sort of
class gets
some work out of the way. If we added enemies to this game
that also fired the projectiles, for instance, we
jectiles to have a different speed than those fired by the player.
It also gets us into the practice of creating classes to control the
feature sets of our game objects, even when they
re not 100%
package {
import flash.display.Sprite;
public class Projectile extends Sprite {
protected var _speed:Number;
public function Projectile(speed:Number = 0) {
this.speed = speed;
public function get speed():Number {
return _speed;
public function set speed(value:Number):void {
_speed = value;
Like I said: simple . The speed variable will be the number of
pixels the projectile will move on every frame cycle.
Search Nedrilad ::

Custom Search