PDA

View Full Version : [AS2] Scoring in Flash


CmndrDemolition
12-15-2009, 12:58 PM
I have two problems with a Flash project I'm working on. First off, I want for the score in my game to increase by one every time a certain object touches another. I set this up with a simple hitTest. However, I want this to be a one time thing (you bump into it once, score goes up by one). right now, if you stay over the intended object, the score continues to go up. how can you limit this?

Secondly, how can you have the Flash file go to a second frame if the score were to reach 100?

neilmmm
12-15-2009, 03:00 PM
outside your on EnterFrame

var hitting:Boolean=false;
CODE]

within your hitTest

[CODE]if (!hitting) {
score++;
score_txt.text=score;
hitting=true;
}[/

when you stop hitTest set hitting back to false

so i guess you would have something like this

var hitting:Boolean = false;
score = 0;
mc.onPress = function() {
this.startDrag();
this.onEnterFrame = function() {
if (this.hitTest(target)) {
if (!hitting) {
score++;
score_txt.text = score;
hitting = true;
}
} else {
hitting = false;
}
};
};