index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="page">
  3. <view class="canvas_box pos_r">
  4. <!-- <view class="tc p20 titlebar">canvas演示</view> -->
  5. <!-- <canvas id="canvasId" class="canvas" /> -->
  6. <div id="game-container" class="bg_ff"></div>
  7. </view>
  8. <view>
  9. <view class="tl mt20 text_color_tips pl20">为方便演示动画,提供功能按钮看效果</view>
  10. <view class="dis_flex_align_between_center p20">
  11. <view class="left dis_flex">
  12. <u-button type="primary" @click="startBom" class="w100">开炮</u-button>
  13. <u-button type="primary" @click="stopBom" class="ml30 w100">停炮</u-button>
  14. </view>
  15. <view class="w300 tc">
  16. <u-button class="w100" type="primary" @click="goUp">向上</u-button>
  17. <view class="dis_flex_align_between_center mt20 mb20">
  18. <u-button type="primary" class="w100" @click="goLeft">向左</u-button>
  19. <u-button type="primary" class="w100" @click="goRight">向右</u-button>
  20. </view>
  21. <u-button type="primary" class="w100" @click="goDown">向下</u-button>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup lang="ts">
  28. import { onMounted, ref } from "vue";
  29. import { onLoad } from "@dcloudio/uni-app";
  30. import Page from "../../libs/pages/Page";
  31. import Game from "@/libs/game/Game";
  32. const title = ref("Hello");
  33. let stage;
  34. let game: any;
  35. const init = () => {
  36. let gameContainer: any = document.getElementById("game-container");
  37. let sysinfo = uni.getSystemInfoSync();
  38. console.log("#debug#🚀 ~ file: index.vue:22 ~ init ~ sysinfo:", sysinfo);
  39. let width = uni.upx2px(sysinfo.screenWidth) * 4; //sysinfo.screenWidth;
  40. let height = uni.upx2px((566 / 750) * width) * 2; // (566 / 750) * width;
  41. gameContainer.style.height = height / 2 + "px"; // sysinfo.safeArea?.height + "px";
  42. gameContainer.style.width = width / 2 + "px"; //sysinfo.safeArea?.right + "px";
  43. game = new Game(gameContainer, width, height);
  44. // game.init();
  45. };
  46. const goLeft = () => {
  47. game.goLeft();
  48. };
  49. const startBom = () => {
  50. game.startBom();
  51. };
  52. const goUp = () => {
  53. game.goUp();
  54. };
  55. const goRight = () => {
  56. game.goRight();
  57. };
  58. const goDown = () => {
  59. game.goDown();
  60. };
  61. const stopBom = () => {
  62. game.stopBom();
  63. };
  64. onLoad(async () => {
  65. uni.setNavigationBarTitle({
  66. title: "动画演示"
  67. });
  68. await Page.Yc.delay(100);
  69. init();
  70. });
  71. </script>
  72. <style lang="scss" scoped>
  73. .page {
  74. .titlebar {
  75. position: absolute;
  76. width: 100%;
  77. left: 0;
  78. top: 0;
  79. }
  80. .btn {
  81. border: solid 1rpx #999;
  82. background-color: #f5f5f;
  83. }
  84. }
  85. </style>