layaair matterjs教程

layaair matterjs教程

$(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);
})

ps:需要引入LayaRender.js 和matterjs.js layaair默认是不引入的

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

原创文章如转载,请注明本文链接: http://newmiracle.cn/?p=3206

发表评论

电子邮件地址不会被公开。 必填项已用*标注