viernes, junio 26, 2009

Adding vibration support

I just added vibration support to both Tomhawk and Rotoroscope. This concrete feature was really simple to implement. I wanted to cover these basic requirements:
  • The support must be offered via Tomahawk's InputManager.
  • I need to create and mantain the vibration effects as separated "assets".
  • The vibration itselft must be defined using two curves, one for each motors in the gamepad.
Given those requirements, this is what I did:

First, I added the RumbleEffect class, which will contain the definition of a vibration effect, including:
  • A name
  • A duration
  • A curve for the left motor
  • A curve for the right motor
Note: For curves, I used the XNA Curves, to be able to use the Curve Editor that's available in the Creators website. We already used these curves in the engine for other subsystems, and this tools itself is included in the Tools folder of the Tomahawk engine.

Thanks to the archetyping feature of the Tomahawk engine, creating a RumbleEffect is as easy as creating the following XML:

Then I added a VibrationManager to the game, in which I defined the VibrationPackage concept. It's nothing more that a collection of RumbleEffects, to be able to define several effects in a single XML file (inlining arquetypes it's supported by Tomahawk).

Also put a public method to invoke a concrete effect, on a concrete gamepad, and voilá... vibration support done!

Now creating the effects itself, it's really easy, just edit the left and right curves using the Curve Editor. The following image shows the curves for the vibration produced when a "bomb" piece explodes:


No hay comentarios: