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个结合的时候 务必保持一致
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/