Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

hitTestObject score increases but it keeps going on..... it should increase only one point

Contributor ,
Aug 28, 2015 Aug 28, 2015

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";

  }

}

TOPICS
ActionScript
517
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 28, 2015 Aug 28, 2015

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";

  }

}

Translate
Community Expert ,
Aug 28, 2015 Aug 28, 2015

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";

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 28, 2015 Aug 28, 2015

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";

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 28, 2015 Aug 28, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 28, 2015 Aug 28, 2015

working fine. thanks a lot

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2015 Aug 29, 2015
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines