Libraries.Interface.Vibration.Vibration Documentation

The Vibration class can be used to start vibration patterns on devices with a vibration motor.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(1000)
            end

        end

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetTimeslice()This method returns the current timeslice length that is used by the Vibration class.
Initialize()This method should be called before the Vibration class is used, so that the vibration control can be acquired.
SetTimeslice(integer timesliceLength)This method changes how long the timeslices in the calculated patterns are in milliseconds when they are called without explicit timeslice length.
Stop()Stops any ongoing vibration
VibrateExponentialPattern(integer duration, integer timeslice)Plays a pattern for the length of duration that increases exponentially in intensity from 0.
VibrateExponentialPattern(integer duration)Plays a pattern for the length of duration that increases exponentially in intensity from 0.
VibrateGeneratedPattern(number intensity, integer duration)Plays a pattern based on an intensity and a duration.
VibrateLinearPattern(integer duration)Plays a pattern for the length of duration that increases linearly in intensity from 0.
VibrateLinearPattern(integer duration, integer timeslice)Plays a pattern for the length of duration that increases linearly in intensity from 0.
VibratePattern(Libraries.Interface.Vibration.PatternArray pattern)This method plays a vibration pattern given in Android's pattern definition.
VibratePattern(Libraries.Interface.Vibration.VibrationArray vibrationArray)This method plays a vibration pattern created with a HapticCommandArray.
VibratePattern(Libraries.Interface.Vibration.PatternArray pattern, integer repetitions)This method plays a vibration pattern given in Android's pattern definition.
VibrateWavePattern(integer duration, integer timeslice)Plays a pattern for the length of duration that changes intensity between 0.
VibrateWavePattern(integer duration)Plays a pattern for the length of duration that changes intensity between 0.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetTimeslice()

This method returns the current timeslice length that is used by the Vibration class.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game

        class Main is Game

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                vibration:Initialize()
                output hm:GetTimeslice()
            end

        end

Return

integer:

Initialize()

This method should be called before the Vibration class is used, so that the vibration control can be acquired. If this method is called before the system is initialized, it will fail.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(1000) 
            end

        end

SetTimeslice(integer timesliceLength)

This method changes how long the timeslices in the calculated patterns are in milliseconds when they are called without explicit timeslice length. The timeslices influence how many different values are computed for a pattern of a certain length. The default timeslice length is 20 ms and should be kept between 5ms and 50ms.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
                vibration:SetTimeSlice(5) // sets timeslices to 5ms
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(1000) 
            end

        end

Parameters

Stop()

Stops any ongoing vibration

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener4

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(600)
            end

            action EndedTouch(TouchEvent event)
                vibration:Stop()
            end

        end

VibrateExponentialPattern(integer duration, integer timeslice)

Plays a pattern for the length of duration that increases exponentially in intensity from 0.0 to 1.0. The duration is measured in milliseconds.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(600)
            end

        end

Parameters

VibrateExponentialPattern(integer duration)

Plays a pattern for the length of duration that increases exponentially in intensity from 0.0 to 1.0. The duration is measured in milliseconds. Timeslice is measured in milliseconds and determines in what intervals the change in intensity is calculated.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(600)
            end

        end

Parameters

VibrateGeneratedPattern(number intensity, integer duration)

Plays a pattern based on an intensity and a duration. This method will take the intensity number to emulate a weaker signal in the same time frame by interspersing the pattern with pauses. The intensity argument is expected to be between 0.0 and 1.0. The duration is measured in milliseconds.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateGeneratedPattern(0.5, 500)
            end

        end

Parameters

VibrateLinearPattern(integer duration)

Plays a pattern for the length of duration that increases linearly in intensity from 0.0 to 1.0. The duration is measured in milliseconds.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(600)
            end

        end

Parameters

VibrateLinearPattern(integer duration, integer timeslice)

Plays a pattern for the length of duration that increases linearly in intensity from 0.0 to 1.0. The duration is measured in milliseconds. Timeslice is measured in milliseconds and determines in what intervals the change in intensity is calculated.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateLinearPattern(600)
            end

        end

Parameters

VibratePattern(Libraries.Interface.Vibration.PatternArray pattern)

This method plays a vibration pattern given in Android's pattern definition. The pattern is an Array of integers. The integers represent instructions to the vibration motor in milliseconds. The first integer represents how long the motor should pause, the second represents how long the motor should run, the third is a pause again, and the fourth is a run instruction again and so forth. This alternating pattern of off and on times can then be used to create complex patterns.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                PatternArray pattern
                pattern:Add(5)
                pattern:Add(100)
                pattern:Add(50) 
                pattern:Add(200) 
                pattern:Add(1000)
                pattern:Add(500) 

                vibration:VibratePattern(pattern) 
            end

        end

Parameters

VibratePattern(Libraries.Interface.Vibration.VibrationArray vibrationArray)

This method plays a vibration pattern created with a HapticCommandArray. The repetition argument allows to repeat the pattern at the index given in the argument. Set to -1 for no repetition.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                VibrationArray pattern
                pattern:LongStrong()
                vibration:VibratePattern(pattern)
            end

        end

Parameters

VibratePattern(Libraries.Interface.Vibration.PatternArray pattern, integer repetitions)

This method plays a vibration pattern given in Android's pattern definition. The pattern is an Array of integers. The integers represent instructions to the vibration motor in milliseconds. The first integer represents how long the motor should pause, the second represents how long the motor should run, the third is a pause again, and the fourth is a run instruction again and so forth. This alternating pattern of off and on times can then be used to create complex patterns. The repetition argument allows to repeat the pattern at the index given in the argument. Set to -1 for no repetition.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                PatternArray pattern
                pattern:Add(5)
                pattern:Add(100)
                pattern:Add(50) 
                pattern:Add(200) 
                pattern:Add(1000)
                pattern:Add(500) 

                vibration:VibratePattern(pattern, 4) // plays through once and then repeats the last two commands
            end

        end

Parameters

VibrateWavePattern(integer duration, integer timeslice)

Plays a pattern for the length of duration that changes intensity between 0.0 and 1.0 in a sin wave form The duration is measured in milliseconds.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibraton:VibrateWavePattern(1000)
            end

        end

Parameters

VibrateWavePattern(integer duration)

Plays a pattern for the length of duration that changes intensity between 0.0 and 1.0 in a sin wave form The duration is measured in milliseconds. Timeslice is measured in milliseconds and determines in what intervals the change in intensity is calculated.

Example Code

use Libraries.Interface.Vibration.Vibration
        use Libraries.Interface.Vibration.VibrationCommand
        use Libraries.Game.Game
        use Libraries.Interface.Events.TouchListener
        use Libraries.Interface.Events.TouchEvent

        class Main is Game, TouchListener

            Vibration vibration

            action Main
                StartGame()
            end

            action CreateGame
                AddTouchListener(me)
                vibration:Initialize()
            end

            action BeganTouch(TouchEvent event)
                vibration:VibrateWavePattern(1000)
            end

        end

Parameters