|
Flash Tutorials - FAQ
Question:
The keyboard control works in flash but doesnt work on the
web page?
Answer:
For keyboard controlled games you need to ensure that the
flash file has the focus, otherwise the keypresses wont be
detected. This short tutorial explains two techniques. How
to ensure that the flash file has the focus
Q:
Is there a printer friendly version of your tutorial?
A:
Yes its here
Q:
There is a typo/bug in the version of the tutorial on flash
kit!
A:
yea I know, the flash kit guys dont seem to have time to change
it - send them an email and give them a nudge. The version
on this site has the typo fixed.
Updated version
of the fla: Ive put together an updated
version of the fla that answers all of the following four
questions in one go!
Q:
How do I keep the player from moving off the stage?
A:
In the updated version
the player cant move off to the left
top or bottom of the stage. The if statments for the player
movement in the spacehip clipEvent have been changed to prevent
movement off the stage.
Q:
How do I add lives to the game?
A:
In the updated version
of the game the player now has 5 lives and loses a life when
colliding with an enemy spaceship.
When all 5 lives are lost the game ends.
To change the number of lives change the value assigned to
the lives variable in the actionscript for the first frame.
ie: change the line
lives = 5;
Two new functions are included in the first frame. These are
: loseLife and resetAllEnemies.
The loseLife function is called when the player collides with
a enemy.
The loseLife function reduces the players
life by one. If the player has no lives left then the game
Over frame is displayed.
function loseLife
() {
resetAllEnemies();
lives--;
if (lives<=0) {
gotoAndStop ("gameOver");
}
}
function resetAllEnemies () {
// this function resets all of the enemies
for (i=1; i<=numEnemy; i++) {
this["enemy"+i].reset();
}
}
Q: How
do I add levels to the game
A: The
updated version has levels,
a new level starts when the player has shot 8 enemies.
The code for counting the enemies shot is in the laser movie
clip's onClipEvent(enterFrame) code.
The function newLevel() below is called when all 8 enemies
are shot.
The newLevel function increases the level number and creates
one new enemy.
function newLevel() {
// This function is called when a new level starts
// it increases the level number and adds one new enemy
level++;
numEnemy++;
enemy1.duplicateMovieClip("enemy"+numEnemy, numEnemy+100);
resetAllEnemies();
}
Q:
How do I stop the player from getting points from hitting
the exploding enemy.
A:
In the updated version
the player no longer gets points from the lasers hitting the
enemy explosion.This is achieved by adding a new varaible
hitFlag which is set to true once the enemy ship has been
hit by a laser.
Q:
How do I make a platform game?
A:
I wrote a case study on platform games for the book flash
games studio - more info here.
Q. How do I make everything scroll down instead of sideways?
A: Ive put together a version
of the final fla that shows how to do this.
Basically it involves changing the code for the stars to scroll
down:
onClipEvent (load) {
stars.duplicateMovieClip("stars2", 1000);
stars2._y = stars._y-stars._height;
starsStartY = this._y;
starsSpeed=4;
}
onClipEvent (enterFrame) {
if (_root.spaceship.scrollStart){
this._y+=starsSpeed;
if (this._y>= (starsStartY+stars._height)){
this._y=starsStartY+starsSpeed;
}
}
}
and then changing the spaceship, ground,
enemy movement and laser movement code.
|