Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Projectiles spawning but not moving.

New Here ,
Dec 01, 2017 Dec 01, 2017

i'm trying to shoot a cannon upon pressing the space key. This is my code, i'm not entirely sure why this isnt working as i have it working on a similar way elsewhere. With the current code it will spawn a missile, but just where the tank is, and not propelling forward.

tank2.addEventListener(Event.ENTER_FRAME, controlGuns);

addEventListener(Event.ENTER_FRAME, gameUpdate);

stage.addEventListener(KeyboardEvent.KEY_DOWN, shootGuns);

addEventListener(Event.ENTER_FRAME, moveMissiles);

stage.focus = stage;

var missileCounts = 0;

function controlGuns(evt: Event) { //Control the gun on only the X axis.

tank2.x = mouseX;

}

function shootGuns(evt: KeyboardEvent) { //Shoot the gun using a switch statement

switch (evt.keyCode) {

case Keyboard.SPACE:

var newMissiles = root["missile" + missileCounts] = this.addChild(new Missile());

newMissiles.x = tank2.x;

newMissiles.y = tank2.y;

newMissiles.width = 15;

newMissiles.height = 15;

var cannonSounds = new CannonSound(); //When shooting, play the audio file

break;

}

}

function moveMissiles(evt: Event) {

for (var i = 1; i <= missileCounts; i++) { //Allow each individual missile to detect if it has hit the ship

root["missile" + i].y += -25;

if (root["missile" + i].hitTestObject(shipArray)) {

}

}

}

TOPICS
ActionScript
260
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2017 Dec 01, 2017
LATEST

i don't see where you're updating missleCounts.  typically that would be done in shootGuns:

function shootGuns(evt: KeyboardEvent) { //Shoot the gun using a switch statement

switch (evt.keyCode) {

case Keyboard.SPACE:

var newMissiles = root["missile" + missileCounts] = this.addChild(new Missile());

missleCounts++

and you need to fix your for-loop

for (var i = 1; i < missileCounts; i++)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines