Skip to content

Extended from EventEmitter CrossPlatformService

This class is used to make the controls functional in any device (Keyboards, Mobiles, Gamepads), this service vinculate actions to specified keys, and also provides a movement system for the player character which can be disabled with the DefaultControllersEnabled property, here is an example to make our player jumps in every device:

--                                  Device,     Key,    Action
CrossPlatformService:SetDeviceKey("Keyboard", "Space", "Jump")
CrossPlatformService:SetDeviceKey("Mobile", "JumpButton", "Jump")
CrossPlatformService:SetDeviceKey("Gamepad", "ButtonA", "Jump")

But this is not limited only to movement actions, you can also assign other kind of actions, for example:

CrossPlatformService:SetDeviceKey("Keyboard", "E", "Collect")
CrossPlatformService:SetDeviceKey("Mobile", "JumpButton", "Collect")
CrossPlatformService:SetDeviceKey("Gamepad", "ButtonA", "Collect")

We assigned an action for our devices but how can we detect when an action is triggered? well we can listen to three events "InputBegin", "InputChange", "InputEnd", example of use:

-- If the movement belongs to a stick, the second parameter will give the current position of the stick
CrossPlatformService:On("InputBegin", function(inputObject)
    local character = CrossPlatformService.Character

    if inputObject.Action == "Jump" then
        character:Jump(150)
    end
end)

Properties

boolean DefaultControllersEnabled

Defines if the default movement system is enabled

boolean SideView

Defines if the character is going to be seen from the side or from the top

number StickSensibility

This is the sensibility of the sticks in mobile and in game controllers

Character Character

This is the character which is going to be tracked by the camera

table Configs

This table stores the default controllers

{
    Keyboard: {
    W: string,
    A: string,
    S: string,
    D: string,
    Up: string,
    Left: string,
    Down: string,
    Right: string,
    Space: string,
},
    Gamepad: {
    ButtonA: string,
    Thumbstick1: {
    Up: string,
    Left: string,
    Down: string,
    Right: string,
},
},
    Mobile: {
    JumpButton: string,
    Thumbstick1: {
    Up: string,
    Left: string,
    Down: string,
    Right: string,
},
},
}

Methods

CrossPlatformService Constructor()

void SetDeviceKey(device: string, key: string, action: string)

Assigns an action to a device key, example:

CrossPlatformService:SetDeviceKey("Keyboard", "Space", "Jump")

void SetDeviceConfig(device: string, controls: Dictionary<string, string>)

Sets the entire configuration of a device, example:

CrossPlatformService:SetDeviceConfig("Keyboard", {
    W = "Up",
    A = "Left",
    S = "Down",
    D = "Right",

    Up = "Up",
    Left = "Left",
    Down = "Down",
    Right = "Right",
    Space = "Jump",
})

void SetPlayerCharacter(character: Character)

Sets the player character

Events

Name
Description
InputBegin Params -> UpsideEngineInput
Fired when one of the keys/sticks in the configuration is pressed/moved
InputChange Params -> UpsideEngineInput
Fired when the an active input change its value, for example the position of a stick
InputEnd Params -> UpsideEngineInput
Fired when one of the keys/sticks in the configuration finish to be pressed/moved