View Full Version : shooting replaces existing bullet
rondog
June 5th, 2007, 06:29 PM
I am shooting a fireball from my character but when I go to hit control again the existing fireball gets erased and replaced with the new one..here is my code
if (Key.isDown(Key.CONTROL)) {
for (k=0; k<99; k++) {
_root.createEmptyMovieClip("fireHolder"+k, depth++);
_root["fireHolder"+k].attachMovie("fireball", "fireball"+k, depth++);
_root["fireHolder"+k]._x = this._x;
_root["fireHolder"+k]._y = this._y;
_root["fireHolder"+k].onEnterFrame = function() {
this._rotation += 20;
if (_root.walker._currentframe == 20) {
this._x += 10;
}
if (_root.walker._currentframe == 10) {
this._x -= 10;
}
};
}
}
Also I need to figure out a better way to determine which way the bullet should shoot..if I shoot it, the IF statements work, but if I turn the other way, the bullet turns around too..hehe kinda funny
Warheart
June 5th, 2007, 08:13 PM
I am shooting a fireball from my character but when I go to hit control again the existing fireball gets erased and replaced with the new one..here is my code
ActionScript Code:
if (Key.isDown(Key.CONTROL)) {
for (k=0; k<99; k++) {
_root.createEmptyMovieClip("fireHolder"+k, depth++);
_root["fireHolder"+k].attachMovie("fireball", "fireball"+k, depth++);
_root["fireHolder"+k]._x = this._x;
_root["fireHolder"+k]._y = this._y;
_root["fireHolder"+k].onEnterFrame = function() {
this._rotation += 20;
if (_root.walker._currentframe == 20) {
this._x += 10;
}
if (_root.walker._currentframe == 10) {
this._x -= 10;
}
};
}
}
Also I need to figure out a better way to determine which way the bullet should shoot..if I shoot it, the IF statements work, but if I turn the other way, the bullet turns around too..hehe kinda funny
I'm thinking the problem is the depth++ in:
_root.createEmptyMovieClip("fireHolder"+k, depth++);
_root["fireHolder"+k].attachMovie("fireball", "fireball"+k, depth++);
try changing it to k...so:
_root.createEmptyMovieClip("fireHolder"+k, k);
_root["fireHolder"+k].attachMovie("fireball", "fireball"+k, k);
-Grant
Hansol
June 5th, 2007, 08:49 PM
Try this to see if the bullet will turn around after its shot.
if (_root.walker._currentframe == 10) {
_root["fireHolder"+k].onEnterFrame = function() {
this._rotation += 20;
this._x -= 10;
};
} else {
if (_root.walker._currentframe == 20) {
_root["fireHolder"+k].onEnterFrame = function() {
this._rotation += 20;
this._x += 10;
};
}
}
nathan99
June 5th, 2007, 10:07 PM
if (Key.isDown(Key.CONTROL)) {
for (k=0; k<99; k++) {
_root.createEmptyMovieClip("fireHolder"+k, depth=depth++ || 0);
_root["fireHolder"+k].attachMovie("fireball", "fireball"+k, depth++);
_root["fireHolder"+k]._x = this._x;
_root["fireHolder"+k]._y = this._y;
_root["fireHolder"+k].onEnterFrame = function() {
this._rotation += 20;
var tmp:Number = _root.walker._currentframe-11;
this._x += 10*(tmp/Math.abs(tmp));
};
}
}
nathan99
June 5th, 2007, 10:16 PM
bit cleaner
if (Key.isDown(Key.CONTROL)) {
for (k=0; k<99; k++) {
var newMC:MovieClip = _root.createEmptyMovieClip("fireHolder"+k, depth=depth++ || 0);
newMC.attachMovie("fireball", "fireball"+k, depth++);
newMC._x = this._x;
newMC._y = this._y;
newMC.onEnterFrame = function() {
this._rotation += 20;
var tmp:Number = _root.walker._currentframe-11;
this._x += 10*(tmp/Math.abs(tmp));
};
}
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.