2012-05-24 6 views
0

공을 끌어다 놓을 수있는 작은 응용 프로그램을 만들고 있습니다. 이 공으로 구를 때면 점이 생기고 공은 임의의 좌표로 이동합니다. 제 문제는 처음 구체를 때리면 위치가 바뀌지 만 다시 치울 수 있다는 것입니다. 여기 당신의 randXrandY 변수는 한 번만 평가받을 것으로 보인다AS3 - 공 잡기

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

답변

0

(드래그 앤 드롭없이) 코드입니다.

따라서 볼의 적중 테스트가 true를 반환하면 구체의 x/y 좌표가 처음 변경되지만 다시는 변경되지 않습니다. 방법을 시도해보십시오.

function hit(event:Event):void 
{ 
    if (ball.hitTestObject(s)) 
    { 
     //s is the sphere 
     s.x = Math.floor(Math.random() * 540) + s.width; 
     s.y = Math.floor(Math.random() * 390) + s.height; // note I changed width to height 
    } 
} 
+0

정말 고맙습니다. :) – Zoske