• Create Account

### #ActualDjMaSh

Posted 07 February 2012 - 06:04 PM

Then I used interfaces for components

Your BaseObject class should just store a list of components. You then derive different component classes, in this case: drawable, updatable, and controllable.

Add instances of these components to a base object instance.

Your main update loop then just iterates over the components of each BaseObject, calling 'Update' or 'Process', which your derived class would have overridden with specific functionality.

eg:

class Component
{
void Update()
}

class BaseObject
{
void RemoveComponent(Component c)

Component components[]
}

//Main loop
foreach(BaseObject b in objects)
foreach(Component c in b.components)
c.Update()


PS I dont remember how to write java code properly so dont expect it to compile

### #1DjMaSh

Posted 07 February 2012 - 06:03 PM

Then I used interfaces for components

Your BaseObject class should just store a list of components. You then derive different component classes, in this case: drawable, updatable, and controllable.

Add instances of these components to a base object instance.

Your main update loop then just iterates over the components of each BaseObject, calling 'Update' or 'Process', which your derived class would have overridden with specific functionality.

eg:

class Component
{
void Update()
}

class BaseObject
{
RemoveComponent(Component c)

Component components[]
}

//Main loop
foreach(BaseObject b in objects)
foreach(Component c in b.components)
c.Update()


PS I dont remember how to write java code properly so dont expect it to compile

PARTNERS