diff --git a/artworld/drawable.js b/artworld/drawable.js
index 05045dd..096fe9f 100644
--- a/artworld/drawable.js
+++ b/artworld/drawable.js
@@ -1,20 +1,26 @@
import { Vector2 } from "./math.js";
import { Color } from "./color.js";
import { Random } from "./random.js";
+import { World } from "./world.js";
export class Drawable {
constructor(parent) {
- this._parent = parent;
- this._updates = [];
+ this._parent = null;
+ this._world = null;
+ // if parent is provided, set directly, then delegate to parent class
+ if (parent instanceof World) {
+ this._world = parent;
+ this._world.drawable(this);
+ } else if (parent) {
+ this._parent = parent;
+ this._parent.addChild(this);
+ }
this._fill = parent ? parent._fill : null;
this._stroke = parent ? parent._stroke : null;
this._strokeWeight = parent ? parent._strokeWeight : null;
this._zIndex = parent ? parent._zIndex : null;
this._posVec = new Vector2(0, 0);
this._animations = [];
- if (this._parent) {
- this._parent.addChild(this);
- }
}
copy() {
@@ -37,6 +43,10 @@ export class Drawable {
}
// setters
+ world(world) {
+ this._world = world;
+ return this;
+ }
fill(color) {
this._fill = color;
@@ -140,8 +150,10 @@ export class Group extends Drawable {
addChild(drawable) {
this._children.push(drawable);
+ // probably alraedy true, but make sure
drawable._parent = this;
- drawable._world = this._world;
+ // ensure we're in the same world
+ drawable.world(this._world);
return this;
}
diff --git a/examples/balls.html b/examples/balls.html
index 4f85eea..cd234fd 100644
--- a/examples/balls.html
+++ b/examples/balls.html
@@ -4,7 +4,7 @@