Microsoft DirectX 8.1 (Visual Basic) |
Create an effect object by using the DirectInputDevice8.CreateEffect method, as in the following code example, where didev is a DirectInputDevice8 object. This example creates a very simple effect that pulls the joystick away from the user at full force for half a second.
Dim effectInfo As DIEFFECT Dim objDIEffect As DirectInputEffect With effectInfo .constantForce.lMagnitude = 10000 .lGain = 10000 .lDuration = 500000 .x = 18000 .lTriggerButton = -1 ' No trigger button End With didev.Acquire Set objDIEffect = didev.CreateEffect("GUID_ConstantForce", effectInfo)
The first parameter to CreateEffect can be one of the predefined GUID aliases, or an actual GUID in string form known from hardware documentation or retrieved for an enumerated effect by using the DirectInputEnumEffects.GetEffectGuid method.
The relevant members of the DIEFFECT type vary according to the kind of effect. Constant forces are the simplest kind, requiring only a single type-specific parameter. The lGain, lDuration, and lTriggerButton members should be set for all effects, since the default values of 0 are not usually suitable.
By default, the direction of the effect is expressed in polar coordinates, meaning that DIEFFECT.x holds the direction from which the force comes, in hundredths of a degree, and DIEFFECT.y must be 0.
Effects are automatically downloaded to the device when created, provided the device is not full and is acquired at the exclusive cooperative level.