imbrn/ace

Change Scene draw API

Closed this issue · 1 comments

imbrn commented

Instead of using this.canvas inside a Scene implementation of draw method, it's more appropriate and favors encapsulation to use canvas as an argument of that.

We can see an example in the moving-ball example:

draw(): void {
this.canvas.fillStyle = "black";
this.canvas.fill(rect({ x: 0, y: 0, width: this.resolution.width, height: this.resolution.height }));
this.canvas.fillStyle = "green";
this.canvas.fill(circle({ x: this.x, y: this.y, radius: 50 }));
}

After this API change it should look like:

draw(canvas: Canvas): void { 
   canvas.fillStyle = "black"; 
   canvas.fill(rect({ x: 0, y: 0, width: this.resolution.width, height: this.resolution.height })); 
    
   canvas.fillStyle = "green"; 
   canvas.fill(circle({ x: this.x, y: this.y, radius: 50 })); 
 }

In this way, we can avoid exposing canvas abstraction to the whole scene but just for the drawing step.

Can I try it? thank you!