Libraries.Interface.Events.TouchListener Documentation

The TouchListener class is used to listen for and react to TouchEvents where the user has begun touching or stopped touching the screen, or is moving a finger across the screen. To use a TouchListener in a program, users should make a new class that inherits from it and overrides TouchBegan, TouchFinished, or TouchContinued.

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
BeganTouch(Libraries.Interface.Events.TouchEvent event)This action is used to respond to a TouchEvent where the user's finger has just touched the screen.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
ContinuedTouch(Libraries.Interface.Events.TouchEvent event)This action is used to respond to a TouchEvent where the user's finger is pressed against the screen.
EndedTouch(Libraries.Interface.Events.TouchEvent event)This action is used to respond to a TouchEvent where the user's finger has just been lifted off of the screen.
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.

Actions Documentation

BeganTouch(Libraries.Interface.Events.TouchEvent event)

This action is used to respond to a TouchEvent where the user's finger has just touched the screen. The event type of the provided TouchEvent should be BEGAN.

Example Code

use Libraries.Interface.TouchEvent
    use Libraries.Interface.TouchListener

    class MyListener is TouchListener

        integer lastX = 0
        integer lastY = 0

        action BeganTouch(TouchEvent event)
            lastX = event:GetX()
            lastY = event:GetY()
        end

    end

Parameters

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

ContinuedTouch(Libraries.Interface.Events.TouchEvent event)

This action is used to respond to a TouchEvent where the user's finger is pressed against the screen. This action can be triggered by either the user keeping their finger stationary on the screen, or moving it across the screen. The event type of the provided TouchEvent should be either MOVED or STATIONARY.

Example Code

use Libraries.Interface.TouchEvent
    use Libraries.Interface.TouchListener

    class MyListener is TouchListener

        integer activeID = -1
        integer distanceX = 0
        integer distanceY = 0

        action BeganTouch(TouchEvent event)
            if activeID = -1
                activeID = event:fingerID
                distanceX = 0
                distanceY = 0
            end
        end

        action ContinuedTouch(TouchEvent event)
            if event:fingerID = activeID
                distanceX = distanceX + event:GetMovementX()
                distanceY = distanceY + event:GetMovementY()
            end
        end

        action EndedTouch(TouchEvent event)
            if event:fingerID = activeID
                activeID = -1
            end
        end

    end

Parameters

EndedTouch(Libraries.Interface.Events.TouchEvent event)

This action is used to respond to a TouchEvent where the user's finger has just been lifted off of the screen. The event type of the provided TouchEvent should be either ENDED or CANCELLED.

Example Code

class MyListener is TouchListener

        boolean isTouched = false

        action BeganTouch(TouchEvent event)
            isTouched = true
        end

        action EndedTouch(TouchEvent event)
            isTouched = false
        end

    end

Parameters

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.