I am not sure how to correctly title this issue.
Basically, when my when my the screen is canvas is supposed to look like this:
However, when I resize the window even slightly, it turns into this:
Everything seems to be stretched weirdly.
As I am new to JS, I am not sure what particularly would be helpful. Here is my "Globals" class, where I hold canvas information:
class Globals{
constructor(){
this.canvas = document.getElementById('game__canvas');
this.ctx = this.canvas.getContext('2d');
this.bg = new Image();
this.bg.src = "https://art.pixilart.com/61f484ce7cee5ad.png";
this.win_h = $(window).height();
this.win_w = $(window).width();
this.canvas_rect = this.canvas.getBoundingClientRect();
this.MAX_BERRIES = 100;
// set dims of canvas
$(window).resize(function(){
this.win_w = window.innerWidth;
this.win_h = window.innerHeight;
this.canvas.width = this.win_w;
this.canvas.height = this.win_h;
});
this.canvas.width = this.win_w;
this.canvas.height = this.win_h;
}
clearListeners(){
// removes all event listeners
var cleared = this.canvas.cloneNode(true);
this.canvas.parentNode.replaceChild(cleared,this.canvas);
}
}
Please let me know if there is anything other things that would help.
Edit:
Here is an error I am getting:
main.js:35 Uncaught TypeError: Cannot set property 'width' of undefined
at main.js:35
at dispatch (jquery.min.js:2)
at v.handle (jquery.min.js:2)
However, I thought that this.canvas.width should be defined, as this.canvas is defined.