Giter Site home page Giter Site logo

weapp-pixi-adapter's Introduction

weapp-adapter for pixi.js

编译

npm install
npm run build

主要改动

输出TouchEvent

官方的adapter并没有把TouchEvent绑定到window,改动也很简单。首先,修改src/EventIniter/TouchEvent.js把默认的TouchEvent类输出:

export default class TouchEvent {
	...
}

随后,修改src/window.js,将其输出即可:

export TouchEvent from './EventIniter/TouchEvent'

关于点击位置映射为题

pixi.js对元素的位置映射有特殊的处理,在其

InteractionManager.prototype.mapPositionToPoint = function mapPositionToPoint(point, x, y) {
        var rect = void 0;

        // IE 11 fix
        if (!this.interactionDOMElement.parentElement) {
            rect = { x: 0, y: 0, width: 0, height: 0 };
        } else {
            rect = this.interactionDOMElement.getBoundingClientRect();
        }

        var resolutionMultiplier = navigator.isCocoonJS ? this.resolution : 1.0 / this.resolution;

        point.x = (x - rect.left) * (this.interactionDOMElement.width / rect.width) * resolutionMultiplier;
        point.y = (y - rect.top) * (this.interactionDOMElement.height / rect.height) * resolutionMultiplier;
    };

会对interactionDOMElementparentElement进行检测,这里的interactionDOMElement元素就是weapp-adapter输出的canvas元素,显然其parentElement元素总是为空的,因此,上述函数总是返回空的区域,为了解决这个问题,有两种方法,一种就是直接覆盖这个函数自己想法重新映射:

PIXI.interaction.InteractionManager.prototype.mapPositionToPoint = (point, x, y) => {
    point.x = x * pixelRatio
    point.y = y * pixelRatio
}

或者

app.renderer.plugins.interaction.mapPositionToPoint = (point, x, y) => {
    point.x = x * pixelRatio
    point.y = y * pixelRatio
}

另外一种就是修改weapp-adaptercanvas对象,将其parentElement设置为true。在src/Canvas.js文件中,增加:

// pixi.js mapPositionToPoint hack
  canvas.__proto__.parentElement = true

这里采用第二种方式。

ajax相关问题

PIXI.loaderajax相关的问题,在src/XMLHttpRequest.js中增加:

addEventListener(ev, cb) {
  this[`on${ev}`] = cb
}

weapp-pixi-adapter's People

Contributors

xmean avatar

Watchers

 avatar

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.