arcade-physics-example.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. <script src="../dist/iife/spine-phaser-v3.js"></script>
  9. <link rel="stylesheet" href="../../index.css" />
  10. <title>Spine Phaser Example</title>
  11. </head>
  12. <body class="p-4 flex flex-col items-center">
  13. <h1>Arcade Physics example</h1>
  14. </body>
  15. <script>
  16. class PhysicsExample extends Phaser.Scene {
  17. preload() {
  18. this.load.spineBinary("coin-data", "/assets/coin-pro.skel");
  19. this.load.spineAtlas("coin-atlas", "/assets/coin-pma.atlas");
  20. }
  21. create() {
  22. const coin = this.add.spine(400, 200, "coin-data", "coin-atlas");
  23. coin.animationState.setAnimation(0, "animation", true);
  24. coin.setScale(0.3);
  25. coin.setSize(280, 280);
  26. this.physics.add.existing(coin);
  27. coin.body.setOffset(0, 50);
  28. coin.body.setVelocity(100, 200);
  29. coin.body.setBounce(1, 1);
  30. coin.body.setCollideWorldBounds(true);
  31. }
  32. }
  33. const config = {
  34. type: Phaser.AUTO,
  35. width: 800,
  36. height: 600,
  37. type: Phaser.WEBGL,
  38. physics: {
  39. default: "arcade",
  40. arcade: {
  41. debug: true,
  42. gravity: { y: 200 },
  43. },
  44. },
  45. scene: [PhysicsExample],
  46. plugins: {
  47. scene: [
  48. {
  49. key: "spine.SpinePlugin",
  50. plugin: spine.SpinePlugin,
  51. mapping: "spine",
  52. },
  53. ],
  54. },
  55. };
  56. const game = new Phaser.Game(config);
  57. </script>
  58. </html>