Forum Topic: AS2 bullet?

(149 views • 2 replies)

This topic is 1 page long.

<< < > >>
Questioning

D-J-S

Reply To Post Reply & Quote

Posted at: 3/30/09 11:47 PM

D-J-S NEUTRAL LEVEL 03

Sign-Up: 05/26/08

Posts: 7

I have this code in my bullet MC

onClipEvent(enterFrame) {
speed = 20
if (_root.char._currentFrame == 1) {
this._x += speed;
this.gotoAndStop(1)
} else {
this._x -= speed;
this.gotoAndStop(2)
}

if (this._x >= 800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else if (this._x <= -800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else {
this.play();
}
}

I made it to the point where the character shoots but when ever it looks left or right the bullet will change direction, how can I have the bullet go one way without it changing direction when the character looks left or right? little help


None

Lard-lad

Reply To Post Reply & Quote

Posted at: 3/31/09 07:47 AM

Lard-lad EVIL LEVEL 07

Sign-Up: 05/30/07

Posts: 483

I think the problem is the first line:

onClipEvent(enterFrame) {

That means whatever is in that block will be executed every frame, which means that it checks which way the bullet should be pointing and moving every frame. You want it to only check when it is first fired, but still do the rest of the script every frame. You need the checking action in (i think) a 'load' event, and the rest in an 'enter frame' event. Try this:

onClipEvent(load) {
speed = 20
if (_root.char._currentFrame == 1) {
this._x += speed;
this.gotoAndStop(1)
} else {
this._x -= speed;
this.gotoAndStop(2)
}
}

onClipEvent(enterFrame) {
if (this._x >= 800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else if (this._x <= -800) {
removeMovieClip(this);
duplicateMovieClip(this,"bullet",3);
this._x = _root.char._x;
this._y = _root.char._y;
} else {
this.play();
}
}

Just click the sig, idiot.

BBS Signature

None

D-J-S

Reply To Post Reply & Quote

Posted at: 4/1/09 12:55 AM

D-J-S NEUTRAL LEVEL 03

Sign-Up: 05/26/08

Posts: 7

yeh i tried that but it duplicates and removes the MC continuously flashing on the screen and it doesn't move.

Don't know why it does this wish I could fix it


All times are Eastern Standard Time (GMT -5) | Current Time: 03:47 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!