diff --git a/src/diveengine2d/RectRenderer.java b/src/diveengine2d/RectRenderer.java index b8e2cb0..19b51e9 100644 --- a/src/diveengine2d/RectRenderer.java +++ b/src/diveengine2d/RectRenderer.java @@ -8,6 +8,10 @@ public class RectRenderer extends DiveScript{ public Color color = null; public int width, height; + public void create() { + name = "Rectangle Renderer"; + } + public void render(Graphics2D g) { g.setColor(color); g.fillRect((int)entity.x, (int)entity.y, width, height); diff --git a/src/diveengine2d/SceneManager.java b/src/diveengine2d/SceneManager.java index 688371a..e1612c2 100644 --- a/src/diveengine2d/SceneManager.java +++ b/src/diveengine2d/SceneManager.java @@ -105,10 +105,21 @@ public class SceneManager { System.out.println("" + componentClass + " is not of type component!"); continue; } - } catch( ClassNotFoundException e ) { - System.out.println("Component " + componentClass + " not found!"); - continue; + } catch( ClassNotFoundException e) { + try { + Object maybeComponent = Class.forName("diveengine2d." + componentClass).newInstance(); + if(maybeComponent instanceof DiveScript) { + component = (DiveScript)maybeComponent; + }else { + System.out.println("" + componentClass + " is not of type component!"); + continue; + } + } catch( ClassNotFoundException ex) { + System.out.println("Component " + componentClass + " not found!"); + continue; + } } + component.create(); component.entity = (Entity) scopeObject.peek(); ((Entity)scopeObject.peek()).addComponent(component); scopeObject.push(component);