4 Replies Latest reply on Jun 26, 2006 8:10 PM by uses_pm4

    Items

    uses_pm4
      I need a code to use for an item. I am working on a game with items (Health and Coins) I use these scripts.

      FOR HEALTH


      onClipEvent (enterFrame) {
      if (this.hitTest(this._parent.dude)) {
      _root.life += 100;
      }
      }


      FOR COINS

      onClipEvent (enterFrame) {
      if (this.hitTest(this._parent.dude)) {
      _root.score += 5;
      }
      }


      I want to know how to make the items dissapear OR stop giving points/health after "dude" or my character touches them.

      Thank you
        • 1. Re: Items
          Level 7
          I'd set up you health items similar to this:

          onClipEvent(load) {
          this.extralife = 100;
          }

          then change you enterFrame to

          onClipEvent (enterFrame) {
          if (this.hitTest(this._parent.dude)) {
          _root.life += this.extralife;
          this.extralife = 0;
          }
          }

          then after the health item has been used, the amount of extra life the healt
          item gives you is set to zero (so cannot get any more from it)

          You could even be clever and have something like this:

          onClipEvent (enterFrame) {
          if (this.hitTest(this._parent.dude)) {
          if (this.extralife > 0) {
          _root.life ++;
          this.extralife --;
          }
          }
          }

          then the longer you hover over the health item, the more health you can get
          from it, until all its 100 points worth are used up. That could be a nice
          feature :)

          NOTE: Similar solution for coins.
          --
          Jeckyl


          • 2. Re: Items
            Craig Grummitt Level 3
            afraid you'll have to do one or the other! as 'health' and 'coins' are very similar problems, i'll just show you your alternatives for health.

            if you want the item to vanish, but still exist, set the visible property:

            onClipEvent (enterFrame) {
            if (this.hitTest(this._parent.dude)) {
            _root.life += 100;
            this._visible=false;
            }
            }

            if you want the item to just stop giving health, set a flag:

            onClipEvent (enterFrame) {
            if (this.hitTest(this._parent.dude) && this.hitme<>true) {
            this.hitme=true; //flag
            _root.life += 100;
            }
            }

            if you want the item to vanish and no longer exist, you'll need to use removeMovieClip. however this only works with movieclips that are added dynamically. you will also need to change your onClipEvent(enterFrame) to onEnterFrame(referencing the instancename that you created dynamically), and place the code on a frame:

            [instancename].onEnterFrame=function() {
            if (this.hitTest(this._parent.dude)) {
            _root.life += 100;
            this.removeMovieClip();
            }
            }
            • 3. Re: Items
              Level 7
              Oh .. ok .. you want to vanish as well

              > onClipEvent (enterFrame) {
              > if (this.hitTest(this._parent.dude)) {
              > _root.life += this.extralife;
              > this.extralife = 0;
              > this._visible = false;
              > }
              > }


              "Jeckyl" <jeckyl@hyde.com> wrote in message
              news:e7q4aj$3h2$1@forums.macromedia.com...
              > I'd set up you health items similar to this:
              >
              > onClipEvent(load) {
              > this.extralife = 100;
              > }
              >
              > then change you enterFrame to
              >
              > onClipEvent (enterFrame) {
              > if (this.hitTest(this._parent.dude)) {
              > _root.life += this.extralife;
              > this.extralife = 0;
              > }
              > }
              >
              > then after the health item has been used, the amount of extra life the
              > healt item gives you is set to zero (so cannot get any more from it)
              >
              > You could even be clever and have something like this:
              >
              > onClipEvent (enterFrame) {
              > if (this.hitTest(this._parent.dude)) {
              > if (this.extralife > 0) {
              > _root.life ++;
              > this.extralife --;
              > }
              > }
              > }
              >
              > then the longer you hover over the health item, the more health you can
              > get from it, until all its 100 points worth are used up. That could be a
              > nice feature :)
              >
              > NOTE: Similar solution for coins.
              > --
              > Jeckyl
              >


              • 4. Re: Items
                uses_pm4 Level 1
                Thanks alot! That helps. I'll post the game when it's done. Anything wrong with it tell me about it. THanks again.