Giter Site home page Giter Site logo

Comments (3)

finscn avatar finscn commented on June 15, 2024

有 示例 项目吗?

from weapp-adapter.

needspeedboy avatar needspeedboy commented on June 15, 2024

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

    }

}


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

from weapp-adapter.

finscn avatar finscn commented on June 15, 2024

这个和 matter无关.

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

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

from weapp-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.