Preparation

All rendering-related operations depend on the renderer, which is provided in the form of the system, so we need to install the renderer on the game when initializing the game. Currently Eva.js provides a 2D renderer, which needs to be installed in advance when using rendering related components.

Install

With NPM

  1. npm i @eva/plugin-renderer

In Browser

  1. <!-- import PixiJS -->
  2. <script src="//unpkg.com/pixi.js@4.8.9/dist/pixi.min.js"></script>
  3. <!-- import RendererAdapter -->
  4. <script src="//unpkg.com/@eva/renderer-adapter@1.2.x/dist/EVA.rendererAdapter.min.js"></script>
  5. <script src="https://unpkg.com/@eva/plugin-renderer@1.2.x/dist/EVA.plugin.renderer.min.js"></script>

Usage

  1. import {Game, GameObject} from '@eva/eva.js'
  2. import {RendererSystem, RENDERER_TYPE} from '@eva/plugin-renderer'
  3. new Game({
  4. systems: [
  5. new RendererSystem({
  6. canvas: document.querySelector('#canvas'), //Optional, automatically generate canvas and mount it on game.canvas
  7. width: 750, //Required
  8. height: 1000, // required
  9. transparent: false, // optional
  10. resolution: window.devicePixelRatio / 2, // Optional, if it is 2 times the image design, it can be divided by 2
  11. enableScroll: true, // Enable page scrolling
  12. renderType: RENDERER_TYPE.UNKNOWN, // RENDERER_TYPE.UNKNOWN: automatic judgment, RENDERER_TYPE.WEBGL/RENDERER_TYPE.CANVAS, it is recommended to use Canvas below android6.1.
  13. backgroundColor: 0xff0000
  14. })
  15. ]
  16. })

Options

canvas

Canvas needed for rendering

width

The width of the rendering canvas, the width of the design draft,

height

The height of the rendering canvas, the height of the design draft

transparent

Whether the background is transparent, the default is false

resolution

Resolution, if the design draft is 2 times (750*1334), you can use window.devicePixelRatio / 2

enableScroll

Whether to Enable page scrolling, the default is true

renderType

Use WebGL or Canvas to render by default to automatically determine whether to support WebGL

backgroundColor

background color

Method

resize(width: number, height: number)

reset rendering canvas size.