0
我剛開始使用FlashPunk,並且在Mac上使用Flash Builder作爲我的IDE。爲什麼doDebug()給我這個錯誤?
我用Box2D和box2fp設置了FlashPunk,我一直在試圖構建一個非常簡單的遊戲。但我的問題是,當我運行doDebug()我收到以下錯誤:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at net.box2fp::Box2DWorld/debug_draw()[/Users/samirghobril/Desktop/MusicGame/src/net/box2fp/Box2DWorld.as:103]
at net.box2fp::Box2DWorld/doDebug()[/Users/samirghobril/Desktop/MusicGame/src/net/box2fp/Box2DWorld.as:123]
at Level1()[/Users/samirghobril/Desktop/MusicGame/src/Level1.as:13]
at Main()[/Users/samirghobril/Desktop/MusicGame/src/Main.as:18]
這裏的Main.as:
package
{
import net.box2fp.Box2DWorld;
import net.flashpunk.Engine;
import net.flashpunk.FP;
import net.flashpunk.Screen;
[SWF(width='800',height='600',backgroundColor='#ffffff',frameRate='60')]
public class Main extends Engine
{
public function Main()
{
super(800, 600, Box2DWorld.DEFAULT_FRAMERATE, true);
FP.world = new Level1;
}
override public function init():void
{
FP.console.enable();
FP.world = new Level1;
}
}
}
而這裏的Level1.as:
package
{
import Box2D.Common.Math.b2Vec2;
import net.box2fp.Box2DWorld;
public class Level1 extends Box2DWorld
{
public function Level1()
{
super();
setGravity(new b2Vec2(0, 10));
doDebug();
}
override public function begin():void
{
add(new Player(80, 600));
}
}
}
而且這裏是Player.as:
package
{
import Box2D.Dynamics.b2Body;
import net.box2fp.Box2DEntity;
import net.box2fp.Box2DShapeBuilder;
public class Player extends Box2DEntity
{
public function Player(x:Number=0, y:Number=0, w:uint=1, h:uint=1, b2Type:int=0)
{
super(x, y, 30, 60, b2Body.b2_dynamicBody);
}
override public function buildShapes(friction:Number, density:Number, restitution:Number, group:int, category:int, collmask:int):void
{
Box2DShapeBuilder.buildRectangle(body, width/(2.0 * box2dworld.scale), height/(2.0 * box2dworld.scale));
}
}
}