Hello SunBurn community!
We'll be out of the office until Monday for the Thanksgiving holiday, we hope everyone has a great weekend!
I will be checking in occasionally to see how things are going, but may not be able to answer some questions until back in the office.
Object-level Components
We've been working on the latest SunBurn 2.0 Game Engine feature - object-level components - and already have a good portion of it up and running. :)
I thought it would be cool to kick off some discussion on the subject as we want a lot of feedback from the community.
So How Does it Work?
SunBurn’s object-level components allow you to plug custom code, behaviors, and modifiers into any entity, scene object, or light.
The system exposes the same object events already available in SunBurn:
UpdateEvent – called once per-frame to apply time based-changes to the object.
CollisionReactEvent – called when the object collides with another object.
CollisionTriggerEvent – called when an object passes through a trigger object.
However instead of writing event handlers for each of these you can write a single component class that takes care of any number of events and can easily be reused, inherited, and more.
Avoiding Component Clutter
One issue we were very careful to avoid is loosely typed components - that is allowing components with specific applications to be assigned to any object type (and in many cases the wrong object type). This causes a lot of confusion, for instance adding a mesh component to a light may not work, why not? Well they were not designed to work together.
SunBurn avoids this by using strongly typed components, which clearly state the relationship between components and their target object types.
Simple Example
As a quick example let’s create a component that works with any scene entity (and also scene objects as they derive from entities), and applies a simple spin to the object:
// Derived from SunBurn's built-in BaseComponent class, but like
// all of SunBurn it's modular and you can implement your own
// using the IComponent interface.
class SpinComponent : BaseComponent<ISceneEntity>
{
public override void OnUpdate(GameTime gametime)
{
// Calculate the elapsed rotation based on the time.
float angle = (float)gametime.ElapsedGameTime.TotalSeconds * 4.0f;
Matrix rotation = Matrix.CreateRotationY(angle);
// Apply the rotation to the parent object (owner of the component).
ParentObject.World = rotation * ParentObject.World;
}
}
This can be plugged into any scene entity, scene object, or avatar, and can be reused, inherited, and more.
Also multiple components can be applied to the same object to stack their features and effects.
Other Uses
Another interesting use for SunBurn components is applying custom properties to an object.
For instance let’s say you want to add the following properties to your game’s destructible scene objects:
Damage – how much damage the object has taken.
Destroyed – whether or not the object is dead or alive.
You could create a DestructibleObject class derived from SceneObject, which is an ok solution.
Or instead you could create a simple component that exposes the properties, and can be plugged into any scene entity or object regardless of which class it’s derived from. Using the component any scene entity or object can become destructible.
class DestructibleComponent : BaseComponent<ISceneEntity>
{
// How much damage the object has taken.
public float Damage { get; set; }
// Whether or not the object is dead or alive.
public bool Destroyed { get; set; }
}
More to Come
There are a lot more awesome features to come, but we definitely want to see some community discussion around SunBurn’s object-level components!
What do you guys think? Let us know!
-John Kabus

Posted
11-25-2010 1:34 AM
by
JohnK "bobthecbuilder"