Skip to main content
Participant
January 23, 2012
Question

Shooting works only when jumping not standing.

  • January 23, 2012
  • 1 reply
  • 359 views

Hi All,

I'm having trouble getting my character to fire. it seems to fire when he jumps, but not while standing. I have attached my code to the zip file below:

http://www.mediafire.com/?jtkke490uzm4k5c

This is the code I used:

---------------------------------------------

onClipEvent (load) {

    var gravity:Number = 0;

    var speed:Number = 5;

    var jumpHeight:Number = 13;

    var scale:Number = _xscale;

    this.gotoAndStop(2);

}

onClipEvent (enterFrame) {

    gravity++;

    _y += gravity;

    while (_root.ground.hitTest(_x, _y, true)) {

        _y--;

        gravity = 0;

    }

    if (Key.isDown(Key.SPACE)) {

        //

        gotoAndPlay("fire");

    }

    if (Key.isDown(Key.RIGHT)) {

        _x += speed;

        _xscale = scale;

        if (_root.ground.hitTest(_x, _y+3, true)) {

            this.gotoAndStop(1);

        } else {

            this.gotoAndStop(2);

        }

    } else if (Key.isDown(Key.LEFT)) {

        _x -= speed;

        _xscale = -scale;

        if (_root.ground.hitTest(_x, _y+3, true)) {

            this.gotoAndStop(1);

        } else {

            this.gotoAndStop(2);

        }

    } else {

        if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {

            this.gotoAndStop(3);

        }

        if (Key.isDown(Key.SPACE)) {

            this.gotoAndPlay("fire");

        }

    }

    if (Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+3, true)) {

        gravity = -jumpHeight;

        this.gotoAndStop(2);

    }

}

----------------------------------------

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
January 24, 2012

that code can't work.  your character can only be on one frame at the end of each loop.  ie, it's on frame 1 or 2 or 3 or "fire".