Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持matter.js吧,强烈请求了。。。 #21

Open
needspeedboy opened this issue Jan 1, 2019 · 3 comments
Open

支持matter.js吧,强烈请求了。。。 #21

needspeedboy opened this issue Jan 1, 2019 · 3 comments

Comments

@needspeedboy
Copy link

单独在开发者环境用matter.js可以,但一用你这插件就不能渲染了也不报错,请作者抽点时间看看能不能解决了。。。

@finscn
Copy link
Owner

finscn commented Feb 15, 2019

有 示例 项目吗?

@needspeedboy
Copy link
Author

//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)               
    

    }

}


上面的代码要是用你们的代理插件将不能运行,关掉就能在微信小游戏里跑。

@finscn
Copy link
Owner

finscn commented Mar 8, 2019

这个和 matter无关.

你不需要再创建 主canvas.
直接 var canvas = window.screencanvas; 就可以了.

你自己再调用 var canvas = wx.createCanvas(); 时, 相当于创建了一个离屏canvas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants