I am trying to make a function inside my class, where by pressing the ArrowUp key, it will become true. However, it just says: "Cannot read property 'key' of undefined?
class Boks{
constructor(x,y,w,h,r,k){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.r = r;
this.k = k;
}
visSnake(){
rect(this.x,this.y,this.w,this.h)
}
moveSnake(){
this.x = this.x + speed;
}
keyb(event){
if(event.key === "ArrowUp"){
return true;
}
}
}
My guess is that I have to define some sort of DOM event key in the constructor or parameter to the constructor, but i dont know how?