phaser icon indicating copy to clipboard operation
phaser copied to clipboard

multi canvas has problem

Open shaoahs opened this issue 7 years ago • 2 comments

Version

  • Phaser Version: 3.16.2
  • Operating system: linux mageia 6
  • Browser: firefox chrome

Description

multi canvas has problem

Example Test Code

graph.js

import m from 'mithril';

let canvasStyle = {
  zIndex: 1,
  position: 'absolute',
  left: '0%',
  top: '0%',
  width: '100%',
  height: '100%'
};
let panelStyle = {
  position: 'absolute',
  zIndex: 9
};

let Component = {

  oninit (vnode) {
    let attrs = vnode.attrs;
    let conf = vnode.attrs.config || {};
    let css = attrs.css;
    if (!css) {
      css = {
        add: 'w-40 h-40 pa1 animated bounceInDown',
        remove: [ 'animated', 'lightSpeedOut' ]
      };
    }
    this.css = css;
    this.config = conf;
    this.scene = attrs.scene;
    this.style = attrs.style;// || normalStyle;
  },

  oncreate (vnode) {
    let config = this.config;
    let scene = this.scene;
    let canvas = vnode.instance.children[0].dom;
    let panel = vnode.instance.children[1].dom;
    let element = {
      canvas: canvas,
      panel: panel,
      root: vnode.dom
    };
    config.element = element;

    if (scene) {
      scene.init(config);
    }
  },

  onbeforeremove (vnode) {
    let element = vnode.dom;
    let css = this.css;

    css.remove.forEach(name => {
      vnode.dom.classList.add(name);
    });
    return new Promise(resolve => {
      element.addEventListener('animationend', ()=> {
        resolve();
        m.redraw();
      });
    });
  },
  // onremove (/*vnode*/) {
  //   console.log('scene onremove');
  // },
  view (vnode) {
    let css = this.css;

    return m('.' + css.add, {
      style: this.style
    },
    m("canvas", {
      style: canvasStyle
    }),
    m('.', {
      style: panelStyle
    }),
    null);
  }
};

export default Component;

main.js

import m from 'mithril';

import graph from 'graph';
import demo from 'demo';

let Application = {
  oninit (/*vnode*/) {
  },
  view () {
    return m('.',
      {
        style: { position: 'absolute', left: '0%', top: '0%', width: '100%', height: '100%'}
      },
      m(graph, 
        {
          scene: demo,
          style: { position: 'absolute', left: '0%', top: '0%', width: '50%', height: '100%'}
        }
      ),
      m(graph, 
        {
          scene: demo,
          style: { position: 'absolute', left: '0%', top: '50%', width: '50%', height: '100%'}
        }
      ),
    );
  }

};
m.mount(document.body, Application)

demo.js

import Phaser from 'phaser';


function init (config) {
  const element = config.element;
  const canvas = element.canvas;

  let preload = function () {
    let load = this.load;
    load.image('logo', 'assets/sprites/phaser.png');

    load.setPath('assets/animations/spine/');
    load.spine('boy', 'spineboy.json', 'spineboy.atlas');
  }
  let create = function () {
    this.add.image(0, 0, 'logo').setOrigin(0);
    this.add.spine(400, 600, 'boy', 'walk', true);
  }

  let conf = {
    type: Phaser.WEBGL,
    canvas: canvas,
    width: 960,
    height: 640,
    render: {
      antialias: true,
      transparent: false
    },
    backgroundColor: '#333333',
    scene: {
      preload: preload,
      create: create,
      pack: {
        files: [
          {
            type: 'scenePlugin',
            key: 'SpineWebGLPlugin',
            url: '/dependence/phaser/plugins/SpineWebGLPlugin.js',
            sceneKey: 'spine'
          }
        ]
      }
    }
  };

  let game = new Phaser.Game(conf);
}

export default {
  init
};

Additional Information

use mithril to manager canvas https://github.com/MithrilJS/mithril.js

shaoahs avatar Feb 19 '19 05:02 shaoahs

I've no idea what this issue is actually reporting, or what mithril is even doing as part of the process. I'm going to flag this as "won't fix" because it sounds like a 3rd party lib interfering with the Phaser canvas. If someone else can resolve it and issue a non-destructive PR I'll gladly merge it.

photonstorm avatar Feb 24 '19 22:02 photonstorm

Closing due to inactivity.

photonstorm avatar Jul 17 '19 13:07 photonstorm