batching-test.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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>Batching test</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. update: update,
  24. pack: {
  25. files: [
  26. {
  27. type: "scenePlugin",
  28. key: "spine.SpinePlugin",
  29. url: "../dist/iife/spine-phaser-v3.js",
  30. sceneKey: "spine",
  31. },
  32. ],
  33. },
  34. },
  35. };
  36. const game = new Phaser.Game(config);
  37. let debug;
  38. function preload() {
  39. this.load.spineJson("raptor-data", "/assets/raptor-pro.json");
  40. this.load.spineAtlas("raptor-atlas", "/assets/raptor-pma.atlas");
  41. this.load.spineBinary("spineboy-data", "/assets/spineboy-pro.skel");
  42. this.load.spineAtlas("spineboy-atlas", "/assets/spineboy-pma.atlas");
  43. }
  44. function create() {
  45. const plugin = this.spine;
  46. let x = 25;
  47. let y = 60;
  48. let n = 0;
  49. for (let j = 0; j < 10; j++, y += 600 / 10) {
  50. for (let i = 0; i < 20; i++, x += 800 / 20) {
  51. const obj =
  52. Math.random() > 0.5
  53. ? this.add.spine(x, y, "spineboy-data", "spineboy-atlas")
  54. : this.add.spine(x, y, "raptor-data", "raptor-atlas");
  55. obj.animationState.setAnimation(0, "walk", true);
  56. obj.scale = 0.1;
  57. n++;
  58. }
  59. x = 25;
  60. }
  61. debug = this.add.text(0, 600 - 40, "FPS: ");
  62. this.add.text(0, 600 - 60, "Skeletons: " + n);
  63. }
  64. function update() {
  65. debug.setText(
  66. "draw calls: " +
  67. spine.PolygonBatcher.getAndResetGlobalDrawCalls() +
  68. "\ndelta: " +
  69. game.loop.delta
  70. );
  71. }
  72. </script>
  73. </html>