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

HitTest problem

New Here ,
Apr 17, 2014 Apr 17, 2014

Copy link to clipboard

Copied

I don`t understand why but when I call hitTest it show "HIT" like 3 sec before it really hit

import flash.events.Event;

this.addEventListener( Event.ENTER_FRAME, handleCollision)

function handleCollision( e:Event 😞void
{
    if(fallingThingsLeft.hitTestObject(Touch1))
       {
           score_txt.text = "HIT"
       }
       else
       {
           score_txt.text = "MISS"
       }
}

import flash.display.Graphics;

import flash.display.MovieClip;

import flash.events.Event;

import flash.events.TimerEvent;

import flash.utils.Timer;

var objectSpawner: Timer;

var fallers: Array;

function initGame(): void {

          fallers = [];

          objectSpawner = new Timer(1000);

          objectSpawner.addEventListener(TimerEvent.TIMER, createEnemy);

          objectSpawner.start();

          addEventListener(Event.ENTER_FRAME, dropEnemies);

}

function createEnemy(e: TimerEvent): void {

          var enemy: Faller = new Faller();

          enemy.y = -stage.stageHeight;

          enemy.x = Math.random() * 380;

          MovieClip(enemy).cacheAsBitmap = true;

          addChild(enemy);

          fallers.push(enemy);

          drawConnectors();

}

function dropEnemies(e: Event): void {

          trace(fallers.length);

          for each(var mc: Faller in fallers) {

                    mc.y += 10;

                    if (mc.y > stage.stageHeight * 2) fallers.splice(fallers.indexOf(removeChild(mc)), 1);

 

          }

          drawConnectors();

}

function drawConnectors(): void {

          if (fallers.length == 0) return;

          var g: Graphics = this.graphics;

          g.clear();

          g.lineStyle(10,0xFFFFFF);

          var mc: Faller = fallers[0];

          g.moveTo(mc.x, mc.y);

          for each(mc in fallers) g.lineTo(mc.x, mc.y);

}

init()

function init():void

{

          var fallingThingsLeft:FallingThings = new FallingThings(stage.stageWidth / 2, stage.stageHeight);

          var fallingThingsRight:FallingThings = new FallingThings(stage.stageWidth / 2, stage.stageHeight);

          addChild(fallingThingsLeft);

          addChild(fallingThingsRight);

          fallingThingsRight.x = stage.stageWidth / 2;

 

}

TOPICS
ActionScript

Views

516

Translate

Translate

Report

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
LEGEND ,
Apr 18, 2014 Apr 18, 2014

Copy link to clipboard

Copied

I am unable to see the relevance between the code your show in the beginning to all that which follows.  Chances are either the fallingThingsLeft or the touch1 object is larger than the eye can see.  Do they happen to involve images that have transparent areas?

Votes

Translate

Translate

Report

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
New Here ,
Apr 18, 2014 Apr 18, 2014

Copy link to clipboard

Copied

Capture d’écran.png

I've highlighted the Touch1 symbol

Votes

Translate

Translate

Report

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
LEGEND ,
Apr 18, 2014 Apr 18, 2014

Copy link to clipboard

Copied

If the fallingThingsLeft object is that other shape, it is possible it is hitting Touch1 because of its bouinding box.

Votes

Translate

Translate

Report

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
New Here ,
Apr 19, 2014 Apr 19, 2014

Copy link to clipboard

Copied

Well, the fallingThingsLeft is falling randomly in a loop so I really don't see where could be the bounding box ??

Votes

Translate

Translate

Report

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
LEGEND ,
Apr 19, 2014 Apr 19, 2014

Copy link to clipboard

Copied

A bounding box surrounds an object.  Two objects can be determined as touching based on their bounding boxes overlapping even though it might appear they do not touch.  You haven't iindicated if the object I mention is the fallingThingsLeft so there isn't much else I can offer.

Votes

Translate

Translate

Report

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
New Here ,
Apr 20, 2014 Apr 20, 2014

Copy link to clipboard

Copied

LATEST

yes the fallingthingsleft is the white line with white ball on angles.So what can I do to have accurate hitTestobject ? remove the bounding box?how?

Votes

Translate

Translate

Report

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