render-to-texture-test.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
  8. <link rel="stylesheet" href="../../index.css" />
  9. <title>Spine Phaser Example</title>
  10. </head>
  11. <body class="p-4 flex flex-col items-center">
  12. <h1>Render to texture</h1>
  13. </body>
  14. <script>
  15. const config = {
  16. type: Phaser.AUTO,
  17. width: 800,
  18. height: 600,
  19. type: Phaser.WEBGL,
  20. scene: {
  21. preload: preload,
  22. create: create,
  23. pack: {
  24. files: [
  25. {
  26. type: "scenePlugin",
  27. key: "spine.SpinePlugin",
  28. url: "../dist/iife/spine-phaser-v3.js",
  29. sceneKey: "spine",
  30. },
  31. ],
  32. },
  33. },
  34. };
  35. const game = new Phaser.Game(config);
  36. function preload() {
  37. this.load.spineBinary("spineboy-data", "/assets/spineboy-pro.skel");
  38. this.load.spineAtlas("spineboy-atlas", "/assets/spineboy-pma.atlas");
  39. }
  40. function create() {
  41. const renderTexture = this.add.renderTexture(400, 300, 800, 600);
  42. console.log(renderTexture.renderMode);
  43. const spineboy = this.add.spine(
  44. 400,
  45. 300,
  46. "spineboy-data",
  47. "spineboy-atlas"
  48. );
  49. spineboy.scale = 0.5;
  50. spineboy.animationState.setAnimation(0, "walk", true);
  51. this.add.text(200, 8, "Click to stamp SpineBoy");
  52. this.input.on(
  53. "pointermove",
  54. function (pointer) {
  55. spineboy.setPosition(pointer.x, pointer.y);
  56. },
  57. this
  58. );
  59. this.input.on(
  60. "pointerdown",
  61. function (pointer) {
  62. renderTexture.draw(spineboy);
  63. spineboy.angle += 10;
  64. },
  65. this
  66. );
  67. }
  68. </script>
  69. </html>