Помогите, я решил попробовать написать игру на Javascript
в своей игре я оспользую некоторое подобие ООП и вот когда я хочу сказать методу Draw
из класса Drawable
он отказывается рисовать, почему? Однако свойство, например fillStyle
изменилось но квадрат не нарисовался.
var canvas = document.getElementById("Game");
var ctx = canvas.getContext("2d");
var Drawable = {
Draw: function(params) {
console.log(params.ctx); //Пишет что это контест Canvas
params.ctx.fillStyle = params.fillStyle || params.ctx.fillStyle;
params.ctx.fillRect(params.x, params.y, params.width, params.height); //Но не рисует
}
}
var Player = {
Player: function() {
},
MoveAt: function(degree) {
degree = degree || this.degree;
this.x += Math.sin(degree) * this.speed;
this.y += Math.cos(degree) * this.speed;
},
x: 0,
y: 0,
speed: 10,
degree: 0,
}
var MainPlayer = new Player.Player();
Drawable.Draw({
ctx: ctx,
fillStyle: "red",
x: MainPlayer.x,
y: MainPlayer.y,
width: 30,
height: 60,
});
<canvas id="Game"></canvas>