I’m making a little app where you can drag and drop a ball. When you hit a sphere with this ball, you get a point and the ball moves to a random cordinate. My problem is that, after you have hitted the sphere the first time, it changes position, but you can hit it again. Here is the code (without the drag and drop)
ball.addEventListener(Event.ENTER_FRAME, hit);
var randX:Number = Math.floor(Math.random() * 540);
var randY:Number = Math.floor(Math.random() * 390);
function hit(event:Event):void
{
if (ball.hitTestObject(s)){ //s is the sphere
s.x = randX + s.width;
s.y = randY + s.width;
}
}
It seems that your
randXandrandYvariables will only get evaluated once.Therefore, if the hit test for the ball returns true, the x/y coordinates of the sphere will change the first time, but never again. How about trying this: