2012-04-28 4 views
0

Acceleropmeter (스마트 폰용)로 볼을 제어 할 수있는 학교용 앱을 만들고 있는데, 공이 특정 Y 좌표에 도달하면 잃어 버리고 이동합니다. (당신이 게임을 잃었다 고 말한) 다른 프레임으로. 공을 수행하고 코드는 지금까지입니다 맞는지 :AS3 - 볼 타격 Y 좌표

var fl_Accelerometer:Accelerometer = new Accelerometer(); 
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler); 

function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void 
{ 
cBall.x -= event.accelerationX * 40; 
cBall.y += event.accelerationY * 40; 
} 

cBall.addEventListener(Event.ENTER_FRAME, moveBall); 
function moveBall(evt:Event){ 

// this is to stop the ball when it tries to exit the sreen 

if(cBall.x > (480-cBall.width/2)){ 
    cBall.x = 480-cBall.width/2; 
} 
    // except for this, that stops the ball not if it touches the end of the screen, but if it reaches a certain Y coordinate 
if(cBall.y > (780-cBall.width/2)){ 
    gotoAndStop(3); 
} 
if(cBall.x < (0+cBall.width/2)){ 
    cBall.x = 0+cBall.width/2; 
} 
if(cBall.y < (0+cBall.width/2)){ 
    cBall.y = 0+cBall.width/2; 
} 
} 

내가 응용 프로그램을 시도 할 때마다, 그것은 32 라인에 오류 (형식 오류가 말한다 : 오류 # 1009 :의 속성이나 메서드에 액세스 할 수 없습니다 null 객체 참조 at ballApp_Scene1_fla :: MainTimeline/moveBall() [ballApp_Scene1_fla.MainTimeline :: frame1 : 32) 이유가 무엇입니까? 이 문제를 어떻게 해결할 수 있습니까?

+0

입니다? 어디서나 선언하거나 어디에서 초기화 할 것인지 모르겠다. –

답변

0

cball은 moveBall 함수에서 사용되는 유일한 객체이므로 null 포인터 예외는 cBall이 아직 초기화되지 않았 음을 의미합니다. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#hitTest%28%29

  • 또는 DisplayObject Class :이 부분은 .. 가능한 더 큰 도움이없는

    을 표시하지만되지 않기 때문에 어쩌면 충돌 탐지를 살펴과

    유사한 물건을하려고 또 다른 하나 cBall 널 (null)이 BitmapData Collision