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;
}
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?
Copy link to clipboard
Copied
I've highlighted the Touch1 symbol
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.
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 ??
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.
Copy link to clipboard
Copied
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?