0
我一直在關注如何在as3中製作一個簡單的高爾夫球遊戲的教程。這個球應該是,當我走動我的手機移動,但由於某種原因,它不會: Golf game image球不移動AS3
這裏是我的外部代碼至今:
package {
import flash.events.Event;
public class golf extends MovieClip {
public function golf() {
stop();
startbtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextScene);
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
ball.addEventListener(Event.ENTER_FRAME, moveBall);
ball.addEventListener(Event.ENTER_FRAME, targethit);
}
var accelX:Number;
var accelY:Number;
var fl_Accelerometer:Accelerometer = new Accelerometer();
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
accelX = event.accelerationX;
accelY = event.accelerationY;
}
function moveBall(evt:Event){
ball.x -= accelX*30;
ball.y += accelY*30;
if(ball.x > (480-ball.width/2)){
ball.x = 480-ball.width/2;
}
if(ball.x < (0+ball.width/2)){
ball.x = 0+ball.width/2;
}
if(ball.y > (800-ball.width/2)){
ball.y = 800-ball.width/2;
}
if(ball.y < (0+ball.width/2)){
ball.y = 0+ball.width/2;
}
}
function targethit(e:Event):void {
if (ball.hitTestObject(hole1)) {
gotoAndStop(1, "End");
}
}
function fl_ClickToGoToNextScene(event:MouseEvent):void
{
MovieClip(this.root).nextScene();
}
}
}
的錯誤,顯示到目前爲止:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at accelerometer()[C:\Users\HP\Downloads\GOLF\accelerometer.as:14]
at runtime::ContentPlayer/loadInitialContent()
at runtime::ContentPlayer/playRawContent()
at runtime::ContentPlayer/playContent()
at runtime::AppRunner/run()
at ADLAppEntry/run()
at global/runtime::ADLEntry()
感謝您的評論!我已經移動了一些代碼並修復了它們被放置的方式,並確定它已修復它! – Nat