The last demo introduced concepts from the HYPE Framework; object pooling and colour pooling. This demo introduces another one, behaviours, and in particular the FixedVibration behaviour, which is based on the HYPE class of the same name. The resulting effect is similar to previous demos, but the animation is much smoother, click the image below to see it.
Below, I’ve included the source code of the demo. You can have a look through all of the code properly on GitHub, but I’ll give a quick overview.
The last two demos had 1000 orbs jittering about on the canvas, but it would be really useful if we could encapsulate this behaviour into a reusable class. FixedVibration does this and allows you to set parameters to affect the behaviour.
When the FixedVibration is created, you specify the target object and the property of that target to apply the behaviour to. This allows you to create multiple behaviours for multiple properties, or even multiple behaviours on the same property.
In order for this behaviour to run I’ve created a BehaviourManager. When updated, the BehaviourManager loops through all added behaviours and runs them. You can see in the code below that the BehaviourManager is updated just before the CanvasController. I’ve also changed the colours for some variation on the previous demos! You can grab the source code from GitHub and have a play.