Mobile Input Handling

Overview

ContextActionService helps effectively manage various input methods such as keyboard, mouse, and touch during gameplay, making it easy to implement context-sensitive interfaces. It allows you to manage player input conveniently and flexibly assign or remove actions based on the game’s context.

Features

  • Can handle multiple input devices such as keyboards, mice, and touch in the same way.

  • Compatible with both OVERDARE Studio environments on PC and mobile platforms, simplifying input handling.

  • Can enable only the necessary inputs depending on specific situations, such as menu screens or gameplay.

  • Provides the ability to distinguish input states via UserInputState, allowing for detailed configuration of actions.

How to Use

1. Creating an Action

You can create an action using the BindAction function in a LocalScript. When creating the action, you can specify the action’s name, whether to create a TouchButton, and the input key to be used on the PC.

local ContextActionService = game:GetService("ContextActionService")

local ActionName = "JumpAction"
local IsCreateTouchButton = true
local KeyCode = Enum.KeyCode.F

local function OnAction(actionName, inputState, inputObject)
    if inputState == Enum.UserInputState.Begin then
        print(actionName .. " triggered!")
    end
end
ContextActionService:BindAction(ActionName, OnAction, IsCreateTouchButton, KeyCode)

The created action can have its text, button image, and position set as follows.

2. Disabling an Action

When a specific action is no longer needed, such as disabling the attack button when entering a shop, you can deactivate it using the UnbindAction function.

3. Handling Input States

You can implement handling for different input states such as input begin, input change, and input end using UserInputState.

Type
Description

Begin

When the input starts

Change

When the input is ongoing

End

When the input ends

Cancel

When the input is interrupted (e.g., when the input point moves out of the button area)

4. Retrieving a Specific Action

You can retrieve a specific button using the GetButton function.

5. Retrieving All Created Actions

You can retrieve all buttons using the GetAllBoundActionInfo function.

Default Input Handling

Mobile Joystick, Jump Button Display Control

You can control the visibility of the mobile joystick and jump button using the SetCoreGuiEnabled function.

Mobile Screen Touch Detection

Use the TouchStarted, TouchMoved, and TouchEnded events to process touch start, movement, and end actions. In the function that connects these events, the input and _gameProcessed variables are delivered as parameters.

  • input: An object containing information related to the touch input point, status, location, etc.

  • _gameProcessed: Returns “true” if the input location overlaps with the UI elements specified below.

    • Native UI, such as the chat window

    • Basic control buttons, such as the joystick and jump button

    • GUI buttons for which “Active” is “true”

    • Actions bound to “BindAction”

Mobile Joystick Input Detection

Last updated