2
This is my function that receives an object and uses the attributes of type "Function".
FrameWork.prototype.loop = function (objectLoop) {
objectLoop.draw();
objectLoop.update();
window.requestAnimationFrame(this.loop.bind(this));
};
This is the object I pass to the loop Function (game is my instance of Framework and Framework is in a separate . js file)
game.loop({
draw : function(){
game.get.Context.clearRect(0, 0, 100, 100);
game.get.Context.fillStyle = colider.color;
game.get.Context.fillRect(colider.x, colider.y, colider.width, colider.height);
game.get.Context.fillStyle = player.color;
game.get.Context.fillRect(player.x, player.y, player.width, player.height);
},
update: function () {
updateBlock();
colide();
wallCollision();
}
});
Error:
Uncaught TypeError: objectLoop.draw is not a function.
It worked! Thank you (it’s funny to be just a detail of this).
– WesFerreira