Pierwszy skrypt:
const canvas = document.getElementById('myCanvas');
const c = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
VAR = {
characters: 0,
screen_width: canvas.width,
screen_heigth: canvas.height,
}
Klasa Hero:
class Hero extends Character{
constructor(){
super();
this.location_x = VAR.screen_width/2;
this.location_y = VAR.screen_height/2;
this.speed = 5;
}
draw() {
c.beginPath();
c.fillStyle = 'Red';
c.fillRect(this.location_x, this.location_y, 10, 10);
c.closePath();
}
}
Plik main. Nie rozumiem dlaczego to nie działa:
function init() {
const hero = new Hero();
hero.draw();
}
init();
A to już tak...:
function init() {
c.beginPath();
c.fillStyle = 'Red';
c.fillRect(200, 200, 10, 10);
c.closePath();
}
init();