Character Coin Collection Confusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chinde
    New Member
    • Feb 2009
    • 52

    Character Coin Collection Confusion

    Hi I'm using AS2 to produce a simple platform game. So far so good I would like the character to collect coins or whatever. so what I have done is create a coin movie clip, I've run a hittest on the coin and my character and when this = true set the coin to _visible = false, move it way off screen and add 10 point to the _global.score. all is working fine but I haven't a clue about having more than one instance of the coin, or more precisely I do have a clue but I don't want to have to name all the instances differently and have reams of if statements (one for each instance). I'm sure that there is an easier way and I guess that I just need some direction.

    I am new to AS2 so please go easy on me.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    The duplicateMovieC lip() method may help you here.

    Comment

    • Chinde
      New Member
      • Feb 2009
      • 52

      #3
      am I right in thinking that the duplicate method requires you to rename each instance?? so if I wanted to refer to a particular instance I would need to still have a separate set of code for each hit test??

      Comment

      • Chinde
        New Member
        • Feb 2009
        • 52

        #4
        I spoke to a some one I know about this, he suggested an array, which I can kind of see his point but I don't really know how to implement it, and he has not used flash before.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          My idea is that, you have your movieclip (with hitTest() in an event handler for it [1]) and then you duplicate that movie clip. You don't have to reference the instance name to work with it (just use this in your hitTest().

          Does that make sense?

          [1]
          Code:
          onClipEvent(mouseMove)
          {
          	if( this.hitTest( _root._xmouse, _root._ymouse, true ) )
          	{
          		this._visible = false;
          	}
          }

          Comment

          • Chinde
            New Member
            • Feb 2009
            • 52

            #6
            Yep, the light dawned this afternoon. I was putting the code into the character and not the object. so from my perspective I had to reference a different coin each time instead of as you suggest, get all the coins to ref the same character. A school boy error, thanks for your time it has helped me get there.

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by Chinde
              Yep, the light dawned this afternoon. I was putting the code into the character and not the object. so from my perspective I had to reference a different coin each time instead of as you suggest, get all the coins to ref the same character. A school boy error, thanks for your time it has helped me get there.
              No problem, friend. We all (in the words of JD, from Scrubs) "have a crystalizing moment when everything becomes clear." Unfortunately, we have the opposite a lot more often!

              - Mark.

              Comment

              • FollowingThefire
                New Member
                • May 2009
                • 5

                #8
                My Hero.

                Originally posted by Markus
                My idea is that, you have your movieclip (with hitTest() in an event handler for it [1]) and then you duplicate that movie clip. You don't have to reference the instance name to work with it (just use this in your hitTest().

                Does that make sense?

                [1]
                Code:
                onClipEvent(mouseMove)
                {
                	if( this.hitTest( _root._xmouse, _root._ymouse, true ) )
                	{
                		this._visible = false;
                	}
                }
                I tried using this code to solve a similar gem problem. using the [this._visible = false;], I put it into my hero. When he hits the gem however, it removes my hero. I am using the arrow keys to move my hero instead of a mouse. My current code.

                Code:
                if (_root.levels.GemTotem.hitTest(_x, _y, true)) {
                		 this._visible = false;
                	}
                GemTotem is the Gem, Levels is the symbol the gem is under. Along with the hero and exit. Any ideas?

                Comment

                • Chinde
                  New Member
                  • Feb 2009
                  • 52

                  #9
                  It sounds exactly like the problem I was having. I moved the code for the hit test from my hero and moved it onto the Coin/Gem type thing. When you use
                  Code:
                  this._dosomething
                  it is referring to the person/place where the code is so when you say
                  Code:
                  this._visible = false;
                  it would make the hero (where you put the code) invisible. Just move the code to the Gem and change all the references there and see what happens.

                  Another problem which I found is that just setting the visibility to false will still leave the item there so, if you are running a scoring system the hero could just stand on the spot and rack up a massive score. In the end I move the object off screen too and this solved that problem.

                  Comment

                  • Chinde
                    New Member
                    • Feb 2009
                    • 52

                    #10
                    In the end I move the object off screen too and this solved that problem.
                    Just realised I might be scolded of advising to do this for memory guzzling reasons.

                    Comment

                    • FollowingThefire
                      New Member
                      • May 2009
                      • 5

                      #11
                      Originally posted by Chinde
                      It sounds exactly like the problem I was having. I moved the code for the hit test from my hero and moved it onto the Coin/Gem type thing. When you use
                      Code:
                      this._dosomething
                      it is referring to the person/place where the code is so when you say
                      Code:
                      this._visible = false;
                      it would make the hero (where you put the code) invisible. Just move the code to the Gem and change all the references there and see what happens.

                      Another problem which I found is that just setting the visibility to false will still leave the item there so, if you are running a scoring system the hero could just stand on the spot and rack up a massive score. In the end I move the object off screen too and this solved that problem.
                      I tried as you said, but for some reason it won't work now. I'm still going to experiment with some things, but at the moment switching it didn't help.

                      Changed and referenced. However, I am new to Flash. Only been learning at school for about 6 - 7 weeks now. I might be forgetting something.

                      Current (not working) code for my gem.

                      Code:
                      onClipEvent (enterFrame) {
                      	if (_root.levels.hero.hitTest(_x, _y, true)) {
                      		 this._visible = false;
                      	}
                      }

                      Comment

                      • Chinde
                        New Member
                        • Feb 2009
                        • 52

                        #12
                        It's been a while since I looked at any AS2 Code (Been up to my neck in VBA) so I am maybe a little rusty and I wasn't 100% even when I was doing a lot of AS2 code.

                        I would try

                        Code:
                        if (this.hitTest(_root.levels.Hero._x, _root.levels.Hero._y, true)) {
                                 this._visible = false;
                            }
                        I guess that the only difference is that I'm being clear on whose _x and _y it should be looking at and I'm switching the hittest to the Gem

                        Comment

                        • Markus
                          Recognized Expert Expert
                          • Jun 2007
                          • 6092

                          #13
                          How strange that you're originally from York. I live in York :)

                          Comment

                          • Chinde
                            New Member
                            • Feb 2009
                            • 52

                            #14
                            I noticed that and I wondered what the with Wolves bit was about, if you mean you live in or near Tanghall I could understand.

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #15
                              Originally posted by Chinde
                              I noticed that and I wondered what the with Wolves bit was about, if you mean you live in or near Tanghall I could understand.
                              I cannot remember whether I was calling my family wolves, or...

                              No not Tanghall, thank god! Strensall, on the outer area of York, near Haxby.

                              Comment

                              Working...