[]物理引擎,我按照官方例子做的,不知道那里写错了,总是报这个错,大神帮我看下

package view
{
import laya.display.Sprite;
import laya.renders.Render;
import laya.utils.Browser;

public class Retitution extends Sprite
{
private const stageWidth:int = 800;
private const stageHeight:int = 600;

private var Matter:Object = Browser.window.Matter;
private var LayaRender:Object = Browser.window.LayaRender;

private var mouseConstraint:*;
private var engine:*;

/***/
public function Retitution()
{
super();

this.width = stageWidth;
this.height = stageHeight;


setup();
}

private function setup():void
{
initMatter();
initWorld();
Laya.stage.on("resize",this,onResize);
}

private function initMatter():void
{
var gameWorld:Sprite = new Sprite();
Laya.stage.addChild(gameWorld);

engine = Matter.Engine.create({enableSleeping:true});
Matter.Engine.run(engine);

var render = LayaRender.create({engine:engine,container:gameWorld,width:stageWidth,height:stageHeight,options:{wireframes:true,showAngleIndicator:true,showCollisions:true,showVelocity:true}});
LayaRender.run(render);

mouseConstraint = Matter.MouseConstraint.create(engine,{element:Render.canvas});
Matter.World.add(engine.world,mouseConstraint);
render.mouse = mouseConstraint.mouse;

}

private function initWorld():void
{
var rest:Number = 0.9;
var space:Number = 600/5;

Matter.World.add(engine.world,
[
Matter.Bodies.rectangle(100+space*0,150,50,50,{ restitution: rest}),
Matter.Bodies.circle(100+space*3,150,25,{ restitution: rest}),
// walls
Matter.Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Matter.Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Matter.Bodies.rectangle(800, 300, 50, 600, { isStatic: true }),
Matter.Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
]);
}

private function onResize():void
{
Matter.Mouse.setScale(mouseConstraint.mouse,{x:1/(Laya.stage.clientScaleX*Laya.stage._canvasTransform.a),y:1/(Laya.stage.clientScaleY*Laya.stage._canvasTransform.d)});
}
}
}



会报错:
Uncaught TypeError: Cannot read property '_color' of null
at WebGLContext2D.__proto.stroke (laya.js:17440)
at RenderContext._drawLine (laya.js:4738)
at GraphicsGL.__proto._renderAll (laya.js:987)
at RenderSprite3D.__proto._graphics (laya.js:5234)
at RenderSprite3D.RenderSprite._initRenderFun [as _fun] (laya.js:5466)
at Sprite.__proto.render (laya.js:18990)
at RenderSprite3D.__proto._childs (laya.js:5305)
at RenderSprite3D.RenderSprite._initRenderFun [as _fun] (laya.js:5466)
at Sprite.__proto.render (laya.js:18990)
at RenderSprite3D.__proto._childs (laya.js:5305)
32laya.js:17440 Uncaught TypeError: Cannot read property '_color' of null
at WebGLContext2D.__proto.stroke (laya.js:17440)
at RenderContext._drawLine (laya.js:4738)
at GraphicsGL.__proto._renderAll (laya.js:987)
at RenderSprite3D.__proto._graphics (laya.js:5234)
at Sprite.__proto.render (laya.js:18990)
at RenderSprite3D.__proto._childs (laya.js:5305)
at Sprite.__proto.render (laya.js:18990)
at RenderSprite3D.__proto._childs (laya.js:5305)
at RenderSprite3D.__proto._transform (laya.js:18012)
at Stage.__proto.render (laya.js:18990)
__proto.stroke @ laya.js:17440
RenderContext._drawLine @ laya.js:4738
__proto._renderAll @ laya.js:987
__proto._graphics @ laya.js:5234
__proto.render @ laya.js:18990
__proto._childs @ laya.js:5305
__proto.render @ laya.js:18990
__proto._childs @ laya.js:5305
__proto._transform @ laya.js:18012
__proto.render @ laya.js:18990
__proto.render @ laya.js:21846
__proto._loop @ laya.js:21780
__proto._enterFrame @ laya.js:4614
setInterval (async)
__proto._onVisibilitychange @ laya.js:4606
__proto.run @ laya.js:7475
__proto.event @ laya.js:322
visibleChangeFun @ laya.js:21598
已邀请:

Laya_XS

赞同来自:

你提交下你具体报错的例子,我们这边查下,别贴代码,这样不方便查找问题!

erwer8363

赞同来自:

官方的两个例子没有报错,但是我自己仿着官网做的,就报错了..貌似一样的代码啊

要回复问题请先

商务合作
商务合作