0
votes

I have the following problem: I want to keep a score when i "hittest". I use the following code:

private function fnMoveMap():void
    {
        for (var i:int = 0; i < vPipeMax; i++)
        {

            var tmpPipe = _conMap.getChildAt(i);
            //trace (tmpPipe.name);

            if (tmpPipe._HIT.hitTestPoint(_P.x, _P.y, true))
            {
                tmpPipe.visible = false;

                //stage.removeEventListener(Event.ENTER_FRAME, setScore);
                vScores++;
                txtScores.text = vScores.toString();
                //break;
            }
            //reset pos
            if (tmpPipe.x < 0)
            {
                //stage.addEventListener(Event.ENTER_FRAME, setScore);
                tmpPipe.visible = true;
                tmpPipe.x = 1050 - vXSpeed;
                tmpPipe.y = randomRangeMC(minPipeY, maxPipeY);
                //set score
                //vScores++;
                //txtScores.text = vScores.toString();
            }
            else
            {
                tmpPipe.x -= vXSpeed;

            }
        }
    }

the var vScores keeps counts for 4 to 8 times. How can i just count one?

1
Well I don't know what vPipeMax is, but you're looping multiple times in that for loop (potentially), so my guess is that's why your score increments by 4-8 each time you trigger it. - snollygolly
vPipeMax is 3. I know its in a loop, but how can i keep it from multiple hittests? - user1631575

1 Answers

0
votes

The reason your vScores variable is incrementing by 4-8 is because you're looping multiple times with the for loop through vPipeMax.

You either need to restructure your code so that doesn't happen, or break out of the loop as soon as you increment the score.