Game Firing problem with key.isDown

  • I looked at the tutorial on how to fire in a game (http://www.kirupa.com/developer/mx/fire.htm) , and tried to replace the clicking the button to hitting the Z button, so it looks like this

    This is the code on pressing the key:
    onEnterFrame = function(){
    if (Key.isDown(90)){
    _root.fire = 1;
    _root.i += .1;
    duplicateMovieClip(_root.bullet, "bullet"+i, i);
    }

    }

    And this is the code on the bullet:
    onClipEvent (load) {
    this._visible = 0;
    if (_root.fire == 1) {
    this._x = _root.player._x;
    this._y = _root.player._y;
    }
    }
    onClipEvent (enterFrame) {
    if (this != _level0.bullet) {
    if (_root.fire == 1) {
    this._y -= 10;
    this._visible = 1;
    }
    if (this._y<0) {
    this.removeMovieClip();
    }
    }
    ..basically the same except replacing "crab" with "player"..

    Now the problem is, when i release the key an extra bullet fires off, and then when i press Z again,that bullet dissappears in mid-air every other time, so is there a way to get that last bullet to just not fire off and be removed?


  • http://www.kirupaforum.com/forums/showthread.php?s=&threadid=38864&highlight=shoot+game

    take a look at the code for shooting, claudio has an attatchment.


  • _root.i += .1;
    duplicateMovieClip(_root.bullet, "bullet"+i, i);

    try making this a + 1 instead of a + .1







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Game Firing problem with key.isDown , Please add it free.

    8 January 2009 | cameltoepants.com | edit