commit all stuff
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
127
src/components/JoyStick.vue
Normal file
127
src/components/JoyStick.vue
Normal file
@@ -0,0 +1,127 @@
|
||||
<style>
|
||||
.vue-joystick {
|
||||
display: inline-block;
|
||||
background: white;
|
||||
height: 256px;
|
||||
width: 256px;
|
||||
border-radius: 50%;
|
||||
position: relative;
|
||||
border: solid 4px var(--color);
|
||||
}
|
||||
.vue-joystick::before,
|
||||
.vue-joystick::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
}
|
||||
.vue-joystick::before {
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: -32px;
|
||||
background: var(--color);
|
||||
height: 64px;
|
||||
width: 64px;
|
||||
border-radius: 50%;
|
||||
transform: translateX(var(--x)) translateY(var(--y));
|
||||
}
|
||||
.vue-joystick::after {
|
||||
left: 126px;
|
||||
bottom: 128px;
|
||||
border-radius: 10px;
|
||||
width: 4px;
|
||||
background: var(--color);
|
||||
transform: rotate(var(--angle));
|
||||
transform-origin: bottom center;
|
||||
height: var(--speed);
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div
|
||||
class="vue-joystick"
|
||||
:style="style"
|
||||
@touchmove="handleTouch"
|
||||
@mousemove="handleMove"
|
||||
@mousedown="handleStart"
|
||||
@mouseup="handleRelease"
|
||||
@touchend="handleRelease"
|
||||
></div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
color: {
|
||||
type: String,
|
||||
default: "#25B"
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
x: 0,
|
||||
y: 0,
|
||||
angle: 0,
|
||||
speed: 0,
|
||||
isMouseDown: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
style() {
|
||||
return {
|
||||
"--x": `${this.x + 128}px`,
|
||||
"--y": `${this.y + 128}px`,
|
||||
"--speed": `${this.speed}px`,
|
||||
"--angle": `${this.angle}deg`,
|
||||
"--color": `${this.color}`
|
||||
};
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleStart() {
|
||||
this.isMouseDown = true;
|
||||
},
|
||||
handleTouch({ touches: [touch] }) {
|
||||
const { clientX, clientY } = touch;
|
||||
const { offsetLeft, offsetTop } = this.$el;
|
||||
const x = Math.round(clientX - offsetLeft - 128);
|
||||
const y = Math.round(clientY - offsetTop - 128);
|
||||
this.updatePosition(x, y);
|
||||
},
|
||||
handleMove({ clientX, clientY }) {
|
||||
if (!this.isMouseDown) {
|
||||
return;
|
||||
}
|
||||
const { offsetLeft, offsetTop } = this.$el;
|
||||
const x = Math.round(clientX - offsetLeft - 128);
|
||||
const y = Math.round(clientY - offsetTop - 128);
|
||||
this.updatePosition(x, y);
|
||||
},
|
||||
handleRelease() {
|
||||
this.emitAll("release");
|
||||
this.isMouseDown = false;
|
||||
this.updatePosition(0, 0);
|
||||
},
|
||||
updatePosition(x, y) {
|
||||
const offset = 128 - 32;
|
||||
const radians = Math.atan2(y, x);
|
||||
const angle = Math.round((radians * 180) / Math.PI, 4);
|
||||
this.angle = angle + (angle > 90 ? -270 : 90);
|
||||
this.speed = Math.min(
|
||||
Math.round(Math.sqrt(Math.pow(y, 2) + Math.pow(x, 2))),
|
||||
128
|
||||
);
|
||||
this.x = this.speed > offset ? Math.cos(radians) * offset : x;
|
||||
this.y = this.speed >= offset ? Math.sin(radians) * offset : y;
|
||||
this.emitAll();
|
||||
},
|
||||
emitAll(name = "change") {
|
||||
this.$emit(name, {
|
||||
x: this.x,
|
||||
y: this.y,
|
||||
speed: this.speed,
|
||||
angle: this.angle
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.emitAll();
|
||||
}
|
||||
};
|
||||
</script>
|
Reference in New Issue
Block a user