index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div ref="gameContainer" class="game-container"></div>
  3. </template>
  4. <script>
  5. import { onMounted, ref } from 'vue';
  6. import Phaser from 'phaser';
  7. export default {
  8. name: 'JumpRope',
  9. setup() {
  10. const gameContainer = ref(null);
  11. onMounted(() => {
  12. // 创建 Phaser 游戏实例
  13. const config = {
  14. type: Phaser.AUTO,
  15. parent: gameContainer.value,
  16. width: 800,
  17. height: 800,
  18. transparent: true, // 设置为透明背景
  19. scene: {
  20. preload,
  21. create,
  22. update,
  23. },
  24. };
  25. new Phaser.Game(config);
  26. let rope, player;
  27. function preload() {
  28. this.load.image('rope', 'static/images/animation/2.png'); // 跳绳的图片
  29. this.load.image('player', 'static/images/animation/1.png'); // 玩家角色的图片
  30. }
  31. function create() {
  32. // 创建跳绳
  33. rope = this.add.image(400, 300, 'rope').setOrigin(0.5, 0.5);
  34. rope.angle = 0;
  35. // 创建玩家角色
  36. player = this.add.image(400, 450, 'player').setOrigin(0.5, 0.5);
  37. // 创建动画
  38. this.tweens.add({
  39. targets: rope,
  40. angle: 360,
  41. duration: 1000,
  42. repeat: -1,
  43. yoyo: true,
  44. ease: 'Sine.easeInOut',
  45. });
  46. }
  47. function update() {
  48. // 每帧更新的逻辑,如果有的话
  49. }
  50. });
  51. return {
  52. gameContainer,
  53. };
  54. },
  55. };
  56. </script>
  57. <style scoped>
  58. .game-container {
  59. width: 100%;
  60. height: 100%;
  61. margin: 0 auto;
  62. position: relative;
  63. }
  64. </style>