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

Variables Table

VariablesDescription
integer STATIONARYThis value represents that a finger is touching the screen and not moving.
integer BEGANThis value represents the event that a finger is first touching the screen.
integer tapCountHow many taps have occurred in a short period of time, including this event (if it is a BEGAN event).
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 ENDEDThis value represents that a finger has been lifted off the screen.
integer yThis variable represents the y-position on the screen where the touch event has occurred.
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 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 MOVEDThis value represents that a finger is moving across the screen.
integer xThis variable represents the x-position on the screen where the touch event has occurred.
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 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 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.

Parameters

Return

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

Example

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

Equals(Libraries.Language.Object object)

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

Parameters

Return

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

Example

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

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetMovementX()

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

Return

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

Example

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

GetMovementY()

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

Return

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

Example

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

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.

Return

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

Example

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

GetX()

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

Return

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

Example

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

GetY()

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

Return

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

Example

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

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.

Parameters

  • boolean handled: Whether or not the event was handled by this listener.

Example

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

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.

Parameters

Example

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

WasEventHandled()

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

Return

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

Example

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