第三次,我需要这些吸盘的帮助。
main.js:
import { Player } from 'classes/player.js';
var canvas = document.getElementById("canvas");
var c = canvas.getContext("2d");
var width = canvas.width;
var height = canvas.height;
c.scale(1, -1);
c.translate(0, -height);
let p = new Player();
p.show();
classes / player.js:
export class Player {
constructor() {
this.cx = 100; //coordinates of the center for operations
this.cy = 838; //coordinates of the center for operations
this.x = this.cx - 25; //coordinates of the corner for drawing
this.y = this.cy + 25; //coordinates of the corner for drawing
this.w = 50;
this.h = 50;
}
show() {
c.fillRect(this.x, this.y, this.w, this.h);
}
}
index.html:
<canvas id='canvas' width=1676 height=755 style="border:1px solid #000000;"></canvas>
<script type='module/javascript' src='main.js'></script>
<script type='module/javascript' src='classes/player.js'></script>
我尝试了所有方法,并且一切正常,直到我添加课程。无论是在单独的模块中还是在main.js中,它永远都不会起作用。拜托,有人帮助,我很绝望。