Copy link to clipboard
Copied
hitTestObject score increases but it keeps going on.....
it should increase only one point when i drag crescent on start but it runs increasing point untill i remove it . any way to fix it ?
var score:Number=0;
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
// test star versus crescent
if (star.hitTestObject(crescent)) {
messageText2.text = "hitTestObject:Yes";
score=score+1;
text1.text=String(score);
} else {
messageText2.text = "hitTestObject: NO";
}
}
my error. use:
var hitBool:Boolean
var score:Number=0;
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
// test star versus crescent
if (star.hitTestObject(crescent)) {
if(!hitBool){
hitBool=true;
messageText2.text = "hitTestObject:Yes";
score=score+1;
text1.text=String(score);
}
} else {
hitBool=false; // <- if you want to allow another hit after a no-hit.
messageText2.text = "hitTestObject: NO";
}
}
Copy link to clipboard
Copied
if the collision continues, score will increase with each loop.
if you only want it to increase once (until there's no hit), use a boolean
var hitBool:Boolean
var score:Number=0;
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
// test star versus crescent
if (star.hitTestObject(crescent)&&!hitBool) {
hitBool=true;
messageText2.text = "hitTestObject:Yes";
score=score+1;
text1.text=String(score);
} else {
hitBool=false; // <- if you want to allow another hit after a no-hit.
messageText2.text = "hitTestObject: NO";
}
}
Copy link to clipboard
Copied
my error. use:
var hitBool:Boolean
var score:Number=0;
addEventListener(Event.ENTER_FRAME, checkCollision);
function checkCollision(event:Event) {
// test star versus crescent
if (star.hitTestObject(crescent)) {
if(!hitBool){
hitBool=true;
messageText2.text = "hitTestObject:Yes";
score=score+1;
text1.text=String(score);
}
} else {
hitBool=false; // <- if you want to allow another hit after a no-hit.
messageText2.text = "hitTestObject: NO";
}
}
Copy link to clipboard
Copied
kglad‌
thanks for your reply . i applied your code . but its same like previous.
here is the link of animation : http://canvas.byethost11.com/forum/CollisionDetection.swf
Copy link to clipboard
Copied
working fine. thanks a lot
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now