Entity and sprite plan

This commit is contained in:
Emily 2020-04-21 15:55:56 +02:00
parent 7e679e3cc3
commit 7165f9ee89
4 changed files with 22 additions and 20 deletions

12
sunpy/canvas/entity.js Normal file
View File

@ -0,0 +1,12 @@
export class Entity {
constructor() {}
async render(renderNode) {}
async update(renderNode) {}
}
export class Sprite extends Entity {
constructor(image) {
if (!(image instanceof Image))
throw TypeError("Image has to be instance of `Image`");
}
}

View File

@ -3,6 +3,7 @@ import { PropertyNode } from "../node/nodes/propertynode.js";
import { PropertyReader, Property } from "../node/propertyreader.js"; import { PropertyReader, Property } from "../node/propertyreader.js";
import { sleep } from "../core/utils.js"; import { sleep } from "../core/utils.js";
import { Vector } from "../core/vector.js"; import { Vector } from "../core/vector.js";
import { Entity } from "./entity.js";
register("canvas", initRenderNode); register("canvas", initRenderNode);
@ -31,7 +32,7 @@ export class RenderNode extends PropertyNode {
this.gl.depthFunc(this.gl.LEQUAL); this.gl.depthFunc(this.gl.LEQUAL);
this.fps = 0; this.fps = 0;
this.objects = []; this.entities = [];
this.running = false; this.running = false;
} }
@ -52,11 +53,11 @@ export class RenderNode extends PropertyNode {
this.running = false; this.running = false;
} }
add(object) { add(entity) {
if (!(object instanceof Renderable)) if (!(entity instanceof Entity))
throw TypeError("Object must be instance of Renderable"); throw TypeError("entity must be instance of `Entity`");
this.objects.push(object); this.entities.push(entity);
} }
async loop() { // TODO: Fix all variables async loop() { // TODO: Fix all variables
@ -83,22 +84,11 @@ export class RenderNode extends PropertyNode {
} }
async render() { async render() {
this.gl.clearColor(0.0, 0.0, 0.0, 1.0); this.gl.clearColor(0.0, 0.0, 0.0, 1.0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT); this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
for (const object of this.objects) { for (const entity of this.entities) {
await object.render(this); await entity.render(this);
} }
} }
} }
export class Renderable {
constructor() {
}
async render(renderNode) {
}
}

View File

@ -6,7 +6,7 @@ export class PropertyNode extends SwapNode {
super(node, swapNode); super(node, swapNode);
if (!(propertyReader instanceof PropertyReader)) if (!(propertyReader instanceof PropertyReader))
throw TypeError("propertyReader must be an instance of PropertyReader"); throw TypeError("propertyReader must be an instance of `PropertyReader`");
this.propertyReader = propertyReader; this.propertyReader = propertyReader;

View File

@ -5,7 +5,7 @@ export class SwapNode extends BaseNode {
super(node); super(node);
if (!(swapNode instanceof Node)) if (!(swapNode instanceof Node))
throw TypeError("swapNode must be instance of Node"); throw TypeError("swapNode must be instance of `Node`");
this.swapNode = swapNode; this.swapNode = swapNode;