Image

The Image component provides the GameObject with the ability to use Image. The Image loaded by resource can be added to the GameObject for display. Renderer needs to be installed before use

Demo

Install

With NPM

  1. npm i @eva/plugin-renderer @eva/plugin-renderer-img

In Browser

  1. <script src="https://unpkg.com/@eva/plugin-renderer-img@1.2.x/dist/EVA.plugin.renderer.img.min.js"></script>

Usage

  1. import {Game, GameObject, resource, RESOURCE_TYPE} from '@eva/eva.js'
  2. import {RendererSystem} from '@eva/plugin-renderer'
  3. import {Img, ImgSystem} from '@eva/plugin-renderer-img'
  4. // Add image resources
  5. resource.addResource([
  6. {
  7. name:'imageName',
  8. type: RESOURCE_TYPE.IMAGE,
  9. src: {
  10. image: {
  11. type: 'png',
  12. url: 'https://gw.alicdn.com/imgextra/i1/O1CN01376pu91tylcmKqXIt_!!6000000005971-2-tps-658-1152.png'
  13. }
  14. },
  15. preload: true
  16. }
  17. ])
  18. // Create game, add renderer
  19. const game = new Game({
  20. systems: [
  21. new RendererSystem({
  22. canvas: document.querySelector('#canvas'),
  23. width: 750,
  24. height: 1000
  25. }),
  26. new ImgSystem()
  27. ]
  28. })
  29. // Create game object
  30. const image = new GameObject('image', {
  31. size: {width: 750, height: 1319 },
  32. origin: {x: 0, y: 0 },
  33. position: {
  34. x: 0,
  35. y: -319
  36. },
  37. anchor: {
  38. x: 0,
  39. y: 0
  40. }
  41. })
  42. // Add Image Component to the game object
  43. image.addComponent(
  44. new Img({
  45. resource:'imageName'
  46. })
  47. )
  48. game.scene.addChild(image)

Options

resource: String

Resource name. The resource name here corresponds to the resource name in the resource information passed in by calling resource.addResource.