Hello, I am trying to develop a simple race game, using almost only Action script. I am in a little bit of trouble because I haven't a lot of experience with this language.
One of the problems is:
I need some trees a the border of the road; I'm doing like this:
in the movie clip of the tree I write code to set the position of the trees and how they have to move; when they exit the stage, I make them re-enter at the starting position. (There is a condition test to determine if the tree is a "right" or a "left" one):
from outside I call:
The problem is that at first the trees move correctly, but then their number decreases until there are no trees left. I cannot understand what's wrong.
I would be very grateful if someone could give me a hint.
One of the problems is:
I need some trees a the border of the road; I'm doing like this:
Code:
duration=1000;
function createtree():Void {
if (i<20) {
attachMovie("tree", "tree"+i, i);
this["tree"+i].dir = Math.floor(Math.random()*2);
i++;
}
}
intervalId = setInterval(this, "createtree", duration);
in the movie clip of the tree I write code to set the position of the trees and how they have to move; when they exit the stage, I make them re-enter at the starting position. (There is a condition test to determine if the tree is a "right" or a "left" one):
Code:
this._xscale = 10;
this._yscale = 10;
this._y = 190;
if (this.dir == 0) {
this._x = 220;
} else {
this._x = 380;
}
function movetree(vel) {
if (this._y>Stage.height) {
this._y = 190;
this._xscale = this._yscale=10;
if (this.dir == 0) {
this._x = 220;
} else {
this._x = 380;
}
}
if (this.dir == 0) {
this._x -= vel*(this._y/190);
} else {
this._x += vel*(this._y/190);
}
this._y += vel;
this._xscale = this._yscale=(this._y-190)+10;
}
Code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
vy += ay;
}
vy *= f;
for (j=1; j<10; j++) {
this["tree"+j].movetree(vy);
}
}
I would be very grateful if someone could give me a hint.