Monday 2 June 2014

A working demo of C/E Systems

Squares and Crabs
There's now a useable demo of this system on https://github.com/autismuk/Comet.

You can see a piccy of it here. It has several components, mostly very basic - position, size, colour, coronaObject, velocity,power and so on.

Then there are two slightly more complex ones that create a sprite and a square respectively.

Because it is a hybrid, the controller isn't a component though. Partly because if it was, you'd have one every time you created an entity. What it is is a link to an instance of the controller.

So what it does is move the crabs and squares round in response to the controller, at varying speeds.

The systems are as follows :

There are position/CO and size/CO and colour/CO that update the corona object from the position, colour and size components.

There's a controller/velocity/power component that updates the velocity from the single controller instance. Power is how fast it goes, the scalar value of the velocity as opposed to the direction which comes from the controller.

Lastly there is a position/velocity component that updates the position from the velocity. This last one uses a thing called deltaTime (okay, I pinched the name from Unity ....) which scales movements to consistent units.

It did strike me that people might know what C/E systems are.

You can read about it here http://en.wikipedia.org/wiki/Entity_component_system

Basically, think of the things on the screen as entities (e.g. each crab is built out of an entity) that are built out of components, which are things like speed, position, alpha, a sprite and so on.

The nifty thing is the automation. If you add a velocity component it automatically moves the position component. If you add a controller component it starts being controlled by it. If you remove it, it takes it away again.

It sounds a bit mad, really. But one of Corona's biggest rivals, Unity3D, works pretty much like this.

No comments:

Post a Comment