我有以下代码但没有任何反应。
Crafty.e('2D, Canvas, Color, Mouse')
.attr({x: 10, y: 10, w: 40, h: 40})
.color('orange')
.bind('Click', function(e){
alert('clicked', MouseEvent);
console.log("hello");
Crafty.log("Clicked right button");
});
我错过了什么吗?
编辑:
使用答案的示例代码:
<template>
<div ref='game' id='game'></div>
</template>
<script>
/* eslint-disable no-unused-vars */
require('@/assets/game/crafty-min.js')
import image from '@/assets/game/background/environment_forest_evening.png'
import button from '@/assets/game/buttons/blank-light-blue-button-md.png'
/* eslint-enable no-unused-vars */
export default{
name: 'game',
data() {
return {
game: null
}
},
mounted: function () {
Crafty.init(500,350, document.getElementById('game'));
// Crafty.canvas.init();
Crafty.e('2D, Canvas, Color, Mouse')
.attr({x: 10, y: 10, w: 40, h: 40})
.color('orange')
.bind('Click', function(e){
alert('clicked', MouseEvent);
console.log("hello");
Crafty.log("Clicked right button");
});
},
methods: {
},
destroyed () {
// this.game.destroy()
},
updated () {
}
}
</script>
<style>
#game {
border: 1px solid black;
margin: auto;
height: 300px;
width: 100%;
}
</style>