|
1 | 1 | <script lang="ts" setup> |
2 | | -import type { Sprite as SpriteElement, SpriteOptions, Texture } from 'pixi.js' |
| 2 | +import type { Sprite as SpriteElement, Texture } from 'pixi.js' |
3 | 3 |
|
4 | | -import { reactive } from 'vue' |
| 4 | +import { computed, reactive } from 'vue' |
5 | 5 | import { onReady, useScreen } from 'vue3-pixi' |
6 | 6 |
|
7 | 7 | type RecordSprite = SpriteElement & Record<string, any> |
8 | 8 |
|
9 | 9 | const screen = useScreen() |
10 | 10 | const textures = reactive<Record<string, Texture>>({}) |
11 | 11 |
|
12 | | -// set some silly values... |
13 | | -const buttons: any[] = [ |
14 | | - { x: 175, y: 75, scale: 1.2 }, |
15 | | - { x: 655, y: 75 }, |
16 | | - { x: 410, y: 325, rotation: Math.PI / 10 }, |
17 | | - { x: 150, y: 465, scale: 0.8 }, |
18 | | - { x: 685, y: 445, scale: { x: 0.8, y: 1.2 }, rotation: Math.PI }, |
19 | | -] |
| 12 | +// calculate button positions and sizes based on screen |
| 13 | +const buttons = computed(() => { |
| 14 | + const { width, height } = screen.value |
| 15 | + return [ |
| 16 | + { x: width * 0.25, y: height * 0.15, scale: 1.2 }, |
| 17 | + { x: width * 0.75, y: height * 0.15 }, |
| 18 | + { x: width * 0.5, y: height * 0.5, rotation: Math.PI / 10 }, |
| 19 | + { x: width * 0.2, y: height * 0.85, scale: 0.8 }, |
| 20 | + { x: width * 0.8, y: height * 0.85, scale: { x: 0.8, y: 1.2 }, rotation: Math.PI }, |
| 21 | + ] |
| 22 | +}) |
20 | 23 |
|
21 | 24 | function onButtonDown(this: RecordSprite) { |
22 | | - this._is_down = true |
| 25 | + this.isDown = true |
23 | 26 | this.texture = textures.buttonDown |
24 | 27 | this.alpha = 1 |
25 | 28 | } |
26 | 29 |
|
27 | 30 | function onButtonUp(this: RecordSprite) { |
28 | | - this._is_down = false |
29 | | - if (this._is_over) |
| 31 | + this.isDown = false |
| 32 | + if (this.isOver) |
30 | 33 | this.texture = textures.buttonOver |
31 | 34 | else |
32 | 35 | this.texture = textures.button |
33 | 36 | } |
34 | 37 |
|
35 | 38 | function onButtonOver(this: RecordSprite) { |
36 | | - this._is_over = true |
37 | | - if (this._is_down) |
| 39 | + this.isOver = true |
| 40 | + if (this.isDown) |
38 | 41 | return |
39 | 42 | this.texture = textures.buttonOver |
40 | 43 | } |
41 | 44 |
|
42 | 45 | function onButtonOut(this: RecordSprite) { |
43 | | - this._is_over = false |
44 | | - if (this._is_down) |
| 46 | + this.isOver = false |
| 47 | + if (this.isDown) |
45 | 48 | return |
46 | 49 | this.texture = textures.button |
47 | 50 | } |
|
0 commit comments