layaair matterjs教程

layaair matterjs教程

<pre>
$(function() {
var Browser = Laya.Browser;
var WebGL = Laya.WebGL;
var Matter = window.Matter;
var LayaRender = window.LayaRender;
var stageWidth = 750;
var stageHeight = 1206;

Laya.init(stageWidth, stageHeight, WebGL);
Laya.stage.scaleMode = "fixedwidth";
// module aliases
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Bodies = Matter.Bodies;
// create an engine
var engine = Engine.create({
enableSleeping: true
});
// engine.world.gravity.y = 0;//关闭重力
// create a renderer
// var render = Render.create({
// element: document.body,
// engine: engine
// });

var render = LayaRender.create({
engine: engine,
width: 750,
height: 1206,
options: {
// background: '../../res/physics/img/background.png',
wireframes: false //true//
}
});
// create two boxes and a ground
var boxA = Bodies.rectangle(100, 200, 750, 10);
var boxB = Bodies.rectangle(450, 50, 47, 47,{render:{
sprite: {
texture: '/fudiqixi/images/2/xiaoqiu.png'
}
} });
var ground = Bodies.rectangle(750/2, 1206/2, 750, 60, {
isStatic: true
});
// add all of the bodies to the world
World.add(engine.world, [boxA, boxB, ground]);
// run the engine
Engine.run(engine);
// run the renderer
// Render.run(render);
LayaRender.run(render);
})
</pre>
ps:需要引入LayaRender.js 和matterjs.js layaair默认是不引入的

matterjs 默认中心点在中间 layaair在左上 2个结合的时候 务必保持一致

posted @ 2019-11-12 15:45  newmiracle宇宙  阅读(325)  评论(0编辑  收藏  举报