Open needspeedboy opened 5 years ago
有 示例 项目吗?
//import as PIXI from './libs/pixi'; import as Matter from './libs/matter'
/**
游戏主函数 */ export default class Main { constructor() { const A = { x: 0, y: 0 }
const B = {
x: 150,
y: 0
}
//window.Image = () => wx.createImage();
var canvas = wx.createCanvas();
canvas.width = 375;
canvas.height = 667;
this.context = canvas.getContext('2d')
this.context.fillStyle = 'red'
this.engine = Matter.Engine.create();
this.boxA = Matter.Bodies.rectangle(A.x, A.y, 30, 30);
this.boxB = Matter.Bodies.rectangle(B.x, B.y, 60, 60);
var ground = Matter.Bodies.rectangle(0, canvas.height - 60, canvas.width, 10, { isStatic: true });
Matter.World.add(this.engine.world, [this.boxA, this.boxB, ground]);
var _f = ()=>{
this.context.clearRect(0, 0, canvas.width, canvas.height)
Matter.Events.trigger(this.engine, 'tick', { timestamp: this.engine.timing.timestamp })
Matter.Engine.update(this.engine, this.engine.timing.delta)
Matter.Events.trigger(this.engine, 'afterTick', { timestamp: this.engine.timing.timestamp })
//console.info(this.boxA.position)
this.context.fillRect(this.boxA.position.x, this.boxA.position.y, 30, 30)
this.context.fillRect(this.boxB.position.x, this.boxB.position.y, 60, 60)
this.context.fillRect(0, canvas.height - 60, canvas.width, 10)
// console.log('boxA', boxA.position);
// console.log('boxB', boxB.position);
}
setInterval(_f.bind(this) , 50)
}
}
上面的代码要是用你们的代理插件将不能运行,关掉就能在微信小游戏里跑。
这个和 matter无关.
你不需要再创建 主canvas.
直接 var canvas = window.screencanvas;
就可以了.
你自己再调用 var canvas = wx.createCanvas();
时, 相当于创建了一个离屏canvas
单独在开发者环境用matter.js可以,但一用你这插件就不能渲染了也不报错,请作者抽点时间看看能不能解决了。。。