Libraries.Interface.Events.TouchEvent Documentation

The TouchEvent class represents an event caused by the user tapping the screen, releasing their finger from the screen, or moving their finger across the screen.

Inherits from: Libraries.Language.Object

Summary

Variable Summary Table

VariablesDescription
integer eventTypeThe eventType field represents what type of touch event this is, or in other words, what is happening that is triggering this touch event. The possible values for it are BEGAN, MOVED, STATIONARY, ENDED, and CANCELLED.
integer tapCountHow many taps have occurred in a short period of time, including this event (if it is a BEGAN event).
integer movementYThis variable represents how far the user's finger has moved on the y-coordinate plane since the last touch event was recorded for that finger.
integer BEGANThis value represents the event that a finger is first touching the screen.
integer MOVEDThis value represents that a finger is moving across the screen.
integer ENDEDThis value represents that a finger has been lifted off the screen.
integer movementXThis variable represents how far the user's finger has moved on the x-coordinate plane since the last touch event was recorded for that finger.
integer fingerIDThis variable represents the particular finger that has triggered this event. If multiple fingers are touching the screen, each finger will have a different ID.
integer xThis variable represents the x-position on the screen where the touch event has occurred.
integer STATIONARYThis value represents that a finger is touching the screen and not moving.
integer yThis variable represents the y-position on the screen where the touch event has occurred.
integer CANCELLEDThis value represents that the system cancelled a touch event, e.g., the user has put the phone to their face while receiving a call.

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.
GetMovementX()This action returns how far the user's finger moved on the x-axis since the last movement event.
GetMovementY()This action returns how far the user's finger moved on the y-axis since the last movement event.
GetSource()This action returns the source item for this event, which is the target of the touch event which has occurred (or is otherwise relevant to it).
GetX()This action returns the x coordinate of where the event was on the screen.
GetY()This action returns the y coordinate of where the event was on the screen.
SetEventHandled(boolean handled)This action sets whether this event should be considered handled by any event listeners.
SetSource(Libraries.Interface.Item item)This action sets the source item for this event, which is the the target of touch event which has occurred (or is otherwise relevant to it).
WasEventHandled()This action returns whether or not this event has already been marked as handled.

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.

GetMovementX()

This action returns how far the user's finger moved on the x-axis since the last movement event.

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

Return

integer: The distance the user's finger has moved on the x-axis since the last TouchEvent.

GetMovementY()

This action returns how far the user's finger moved on the y-axis since the last movement event.

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

Return

integer: The distance the user's finger has moved on the y-axis since the last TouchEvent.

GetSource()

This action returns the source item for this event, which is the target of the touch event which has occurred (or is otherwise relevant to it). In the Game engine, if an Item is clicked directly, it will be stored here. If a MouseEvent is triggered with no such Item available, this will be undefined.

Example Code

use Libraries.Game.Game
    use Libraries.Interface.Events.MouseEvent
    use Libraries.Interface.Events.MouseListener
    use Libraries.Interface.Item
    use Libraries.Game.Graphics.Drawable

    class Main is Game, MouseListener

        Drawable square

        action Main
            StartGame()
        end

        action CreateGame
            square:LoadFilledRectangle(200, 200)
            square:SetPosition(300, 200)
            Add(square)

            AddMouseListener(me)
        end

        action ClickedMouse(MouseEvent event)
            Item source = event:GetSource()

            if source = undefined
                output "The background was clicked!"
            elseif source:Equals(square)
                output "The square was clicked!"
            end
        end
    end

Return

Libraries.Interface.Item: The source Item for this MouseEvent.

GetX()

This action returns the x coordinate of where the event was on the screen.

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

Return

integer: The x-coordinate of the point on the screen that was touched.

GetY()

This action returns the y coordinate of where the event was on the screen.

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

Return

integer: The y-coordinate of the point on the screen that was touched.

SetEventHandled(boolean handled)

This action sets whether this event should be considered handled by any event listeners. This is typically used when using multiple listeners, in order to ensure that a TouchListener doesn't process a TouchEvent that was already handled by a different one.

Example Code

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

    class MyListener is TouchListener

        action BeganTouch(TouchEvent event)
            if event:GetX() < 100
                event:SetEventHandled(true)
            else
                event:SetEventHandled(false)
            end
        end

    end

Parameters

SetSource(Libraries.Interface.Item item)

This action sets the source item for this event, which is the the target of touch event which has occurred (or is otherwise relevant to it). In the Game engine, if an Item is tapped directly, it will be stored here. If a TouchEvent is triggered with no such Item available, this will be undefined.

Example Code

use Libraries.Game.Game
    use Libraries.Interface.Events.TouchEvent
    use Libraries.Interface.Events.TouchListener
    use Libraries.Interface.Item2D

    class Main is Game, TouchListener

        action Main
            StartGame()
        end

        action CreateGame
            AddTouchListener(me)
        end

        action BeganTouch(TouchEvent event)
            if event:GetSource() not= undefined
                return now
            end

            Item2D newItem
            event:SetSource(newItem)
            event:SetEventHandled(false)
        end
    end

Parameters

WasEventHandled()

This action returns whether or not this event has already been marked as handled.

Example Code

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

    class MyListener is TouchListener

        integer counter = 0

        action BeganTouch(TouchEvent event)
            if event:WasEventHandled()
                return now
            end

            counter = counter + 1
            event:SetEventHandled(true)
        end

    end

Return

boolean: Whether or not the event was has already been handled.