vanilladocs
vanillapunch.com
API / core/gamepadmanager

core/gamepadmanager

입력 매니저.

Input manager.

GamepadManagerextends Object

짝Counterpart: vanilla-engine GamepadManager

입력 매니저.

Input manager.

예제Example패드 단추와 스틱 읽기Read pad buttons and sticks
import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";

class MainScene extends Scene {
	tick(timeDelta) {
		super.tick(timeDelta);
		const engine = this.getEngine();
		const inputManager = engine.getInputManager();
		const gamepadManager = inputManager.getGamepadManager();
		const gamepads = gamepadManager.getAllConnectedGamepads();
		for (const gamepad of gamepads) {
			if (gamepadManager.isButtonJustPressed(gamepad.index, 0)) {
				console.log("jump", gamepad.id);
			}
			const horizontal = gamepadManager.getAxisValue(gamepad.index, 0);
			if (Math.abs(horizontal) > 0.2) {
				console.log("move", horizontal);
			}
		}
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const inputManager = engine.getInputManager();
const gamepadManager = inputManager.getGamepadManager();
gamepadManager.setCallback((gamepadIndex, inputType, inputIndex, value) => {
	console.log(gamepadIndex, inputType, inputIndex, value);
});
engine.run(new MainScene());
생성자constructorconstructor(engine)#0.0.9 부터since 0.0.9소스source

생성.

Constructor.

engineEngine
이 매니저를 가진 엔진. (쓰지 않는다)The engine that owns this manager. (not used)

짝Counterpart: vanilla-engine GamepadManager.new

메서드methodtick(timeDelta)#0.0.9 부터since 0.0.9소스source

갱신.

Update.

timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)

짝Counterpart: vanilla-engine GamepadManager.tick

메서드methodconnect(gamepad)#0.0.9 부터since 0.0.9소스source

게임패드 연결.

Gamepad connected.

gamepadGamepad
붙일 게임패드. (null 이거나 이미 붙은 번호면 아무것도 하지 않는다)Gamepad to attach. (does nothing if null or its index is already attached)

짝Counterpart: vanilla-engine GamepadManager.connect

메서드methoddisconnect(gamepad)#0.0.9 부터since 0.0.9소스source

게임패드 연결 해제.

Gamepad disconnected.

gamepadGamepad
놓을 게임패드. (붙지 않은 번호면 아무것도 하지 않는다)Gamepad to release. (does nothing if its index is not attached)

짝Counterpart: vanilla-engine GamepadManager.disconnect

메서드methodsetCallback(callback)#0.0.9 부터since 0.0.9소스source

콜백 설정.

Sets the callback.

callback(gamepadIndex: number, inputType: "button" | "value" | "axis", inputIndex: number, value: any) => void
단추나 축이 바뀔 때 부를 함수. (button 은 눌림 참 거짓, value 는 0 보다 큰 아날로그 값, axis 는 -1 ~ 1, null 이면 부르지 않는다)Function called when a button or axis changes. (button gives pressed true or false, value gives an analog value above 0, axis gives -1 ~ 1; not called if null)

짝Counterpart: vanilla-engine GamepadManager.set_callback

메서드methodupdateAllGamepads()#0.0.9 부터since 0.0.9소스source

모든 게임패드 갱신.

Updates all gamepads.

짝Counterpart: vanilla-engine GamepadManager.update_all_gamepads

메서드methodisButtonPressed(gamepadIndex, buttonIndex)#0.0.9 부터since 0.0.9소스source

버튼 눌림 상태 반환.

Returns the button pressed state.

gamepadIndexnumber
패드 번호. (Gamepad.index)Pad index. (Gamepad.index)
buttonIndexnumber
단추 번호. (W3C 표준 매핑, 0 이 A 나 크로스 단추)Button index. (W3C standard mapping, 0 is the A or cross button)

반환Returnsboolean 눌려 있으면 참. (없는 패드나 단추면 거짓)True if held down. (false for a missing pad or button)

짝Counterpart: vanilla-engine GamepadManager.is_button_pressed

메서드methodisButtonJustPressed(gamepadIndex, buttonIndex)#0.4.0 부터since 0.4.0소스source

이번 갱신에 방금 눌린 버튼인지. (키보드 isKeyJustPressed 와 같은 쓰임)

Whether the button was just pressed in this update. (same use as keyboard isKeyJustPressed)

gamepadIndexnumber
패드 번호. (Gamepad.index)Pad index. (Gamepad.index)
buttonIndexnumber
단추 번호. (W3C 표준 매핑, 0 이 A 나 크로스 단추)Button index. (W3C standard mapping, 0 is the A or cross button)

반환Returnsboolean 이번 갱신에 눌렸으면 참.True if pressed in this update.

짝Counterpart: vanilla-engine GamepadManager.is_button_just_pressed

메서드methodisButtonJustReleased(gamepadIndex, buttonIndex)#0.4.0 부터since 0.4.0소스source

이번 갱신에 방금 떼어진 버튼인지.

Whether the button was just released in this update.

gamepadIndexnumber
패드 번호. (Gamepad.index)Pad index. (Gamepad.index)
buttonIndexnumber
단추 번호. (W3C 표준 매핑, 0 이 A 나 크로스 단추)Button index. (W3C standard mapping, 0 is the A or cross button)

반환Returnsboolean 이번 갱신에 떼어졌으면 참.True if released in this update.

짝Counterpart: vanilla-engine GamepadManager.is_button_just_released

메서드methodgetButtonValue(gamepadIndex, buttonIndex)#0.0.9 부터since 0.0.9소스source

버튼/트리거 아날로그 값 반환 (0.0 ~ 1.0).

Returns the button/trigger analog value (0.0 ~ 1.0).

gamepadIndexnumber
패드 번호. (Gamepad.index)Pad index. (Gamepad.index)
buttonIndexnumber
단추 번호. (W3C 표준 매핑, 0 이 A 나 크로스 단추)Button index. (W3C standard mapping, 0 is the A or cross button)

반환Returnsnumber 아날로그 값. (0 ~ 1, 소수 둘째 자리까지, 없으면 0)Analog value. (0 ~ 1, to two decimal places, 0 if missing)

짝Counterpart: vanilla-engine GamepadManager.get_button_value

메서드methodgetAxisValue(gamepadIndex, axisIndex)#0.0.9 부터since 0.0.9소스source

아날로그 스틱 축 값 반환 (-1.0 ~ 1.0).

Returns the analog stick axis value (-1.0 ~ 1.0).

gamepadIndexnumber
패드 번호. (Gamepad.index)Pad index. (Gamepad.index)
axisIndexnumber
축 번호. (0 왼쪽 가로, 1 왼쪽 세로, 2 오른쪽 가로, 3 오른쪽 세로)Axis index. (0 left horizontal, 1 left vertical, 2 right horizontal, 3 right vertical)

반환Returnsnumber 축 값. (-1 ~ 1, 소수 둘째 자리까지, 없으면 0)Axis value. (-1 ~ 1, to two decimal places, 0 if missing)

짝Counterpart: vanilla-engine GamepadManager.get_axis_value

메서드methodgetAllConnectedGamepads()#0.0.9 부터since 0.0.9소스source

연결된 모든 게임패드 반환.

Returns all connected gamepads.

반환ReturnsGamepad[] 연결된 게임패드 목록. (브라우저의 지금 Gamepad)List of connected gamepads. (the browser's current Gamepad objects)

짝Counterpart: vanilla-engine GamepadManager.get_all_connected_gamepads

메서드methodgetConnectedGamepadCount()#0.0.9 부터since 0.0.9소스source

연결된 게임패드 수 반환.

Returns the number of connected gamepads.

반환Returnsnumber 연결된 게임패드 수.Number of connected gamepads.

짝Counterpart: vanilla-engine GamepadManager.get_connected_gamepad_count

메서드methodgetConnectedGamepad(gamepadIndex)#0.0.9 부터since 0.0.9소스source

연결된 게임패드 반환.

Returns the connected gamepad.

gamepadIndexnumber
연결된 차례의 번호. (0 ~ 연결 수 - 1, Gamepad.index 가 아니다)Index in connection order. (0 ~ connected count - 1, not Gamepad.index)

반환ReturnsGamepad | undefined 그 차례의 게임패드. (범위 밖이면 undefined)The gamepad at that position. (undefined if out of range)

짝Counterpart: vanilla-engine GamepadManager.get_connected_gamepad

메서드methodsetInputLogEnabled(isEnabled)#0.4.0 부터since 0.4.0소스source

단추와 축이 바뀔 때마다 콘솔에 찍을지 설정. (기본은 끔, 연결과 해제는 늘 찍는다)

Sets whether to log to the console whenever buttons and axes change. (off by default, connection and disconnection are always logged)

isEnabledboolean
참이면 콘솔에 찍는다.If true, logs to the console.

짝Counterpart: vanilla-engine GamepadManager.set_input_log_enabled

메서드methodisInputLogEnabled()#0.4.0 부터since 0.4.0소스source

단추와 축이 바뀔 때마다 콘솔에 찍는지 반환.

Returns whether to log to the console whenever buttons and axes change.

반환Returnsboolean 콘솔에 찍으면 참.True if logging to the console.

짝Counterpart: vanilla-engine GamepadManager.is_input_log_enabled

메서드methodgetActiveGamepadId()#0.4.0 부터since 0.4.0소스source

마지막 갱신에 단추를 누르거나 축을 크게 기울인 패드의 이름 반환. (없으면 빈 글, 마지막으로 쓴 장치를 가릴 때)

Returns the name of the pad whose button was pressed or axis tilted far in the last update. (empty string if none, to tell the last used device)

반환Returnsstring 패드 이름. (Gamepad.id, 없으면 빈 글)Pad name. (Gamepad.id, empty text if none)

짝Counterpart: vanilla-engine GamepadManager.get_active_gamepad_id

메서드methodvibrate(strongMagnitude, weakMagnitude, seconds)#0.4.0 부터since 0.4.0소스source

연결된 패드를 모두 떨기. (세기는 0 ~ 1, 브라우저 Gamepad.vibrationActuator 의 dual-rumble)

  • 진동 장치가 없는 패드와 브라우저(사파리 등)는 건너뛴다.
  • 앞의 진동이 끝나기 전에 다시 부르면 새 진동으로 바뀐다. (브라우저가 앞 약속을 거절하는 것은 흘린다)

Vibrates all connected pads. (strength 0 ~ 1, dual-rumble of the browser's Gamepad.vibrationActuator)

  • Pads without a vibration actuator and browsers (Safari, etc.) are skipped.
  • Calling again before the previous vibration ends replaces it with the new one. (the browser rejecting the previous promise is ignored)
strongMagnitudenumber
무거운 모터의 세기. (묵직한 울림)Strength of the heavy motor. (deep rumble)
weakMagnitudenumber
가벼운 모터의 세기. (잘게 떨림)Strength of the light motor. (fine vibration)
secondsnumber
떠는 시간. (초)Vibration time. (seconds)

짝Counterpart: vanilla-engine GamepadManager.vibrate

예제Example연결된 패드를 0.25 초 떨기Rumble connected pads for 0.25 seconds
import { Engine, EngineConfiguration } from "./build/vanilla.js";

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const inputManager = engine.getInputManager();
const gamepadManager = inputManager.getGamepadManager();
gamepadManager.vibrate(1, 0.3, 0.25);
const connectedGamepadCount = gamepadManager.getConnectedGamepadCount();
console.log(connectedGamepadCount);

함수Functions

함수functionreadGamepadKind(gamepadId)#0.4.0 부터since 0.4.0소스source

패드 이름으로 종류 가르기. (플레이스테이션 054c, 닌텐도 057e, 엑스박스 045e 와 이름, 모르면 other)

Classifies the type by pad name. (PlayStation 054c, Nintendo 057e, Xbox 045e and names, other if unknown)

gamepadIdstring
Gamepad.id

반환Returnsstring GamepadKind 의 값.A GamepadKind value.

짝Counterpart: vanilla-engine read_gamepad_kind

GamepadAnalogStickCodeenum

짝Counterpart: vanilla-engine GamepadAnalogStickCode

게임패드 아날로그 스틱 식별자. (W3C Standard Gamepad 매핑 규격)

Gamepad analog stick identifiers. (W3C Standard Gamepad mapping)

이름Name값Value설명Description
LEFT_X0왼쪽 스틱 가로축.Left stick horizontal axis.
LEFT_Y1왼쪽 스틱 세로축.Left stick vertical axis.
RIGHT_X2오른쪽 스틱 가로축.Right stick horizontal axis.
RIGHT_Y3오른쪽 스틱 세로축.Right stick vertical axis.

GamepadTriggerCodeenum

짝Counterpart: vanilla-engine GamepadTriggerCode

게임패드 트리거 식별자. (W3C Standard Gamepad 매핑 규격)

Gamepad trigger identifiers. (W3C Standard Gamepad mapping)

이름Name값Value설명Description
L26왼쪽 트리거.Left trigger.
R27오른쪽 트리거.Right trigger.

GamepadButtonCodeenum

짝Counterpart: vanilla-engine GamepadButtonCode

게임패드 버튼 식별자. (W3C Standard Gamepad 매핑 규격)

Gamepad button identifiers. (W3C Standard Gamepad mapping)

이름Name값Value설명Description
A_CROSS0Face Buttons
B_CIRCLE1오른쪽 얼굴 단추. (엑스박스 B, 플레이스테이션 동그라미)Right face button. (Xbox B, PlayStation circle)
X_SQUARE2왼쪽 얼굴 단추. (엑스박스 X, 플레이스테이션 네모)Left face button. (Xbox X, PlayStation square)
Y_TRIANGLE3위쪽 얼굴 단추. (엑스박스 Y, 플레이스테이션 세모)Top face button. (Xbox Y, PlayStation triangle)
L14Bumpers
R15오른쪽 범퍼.Right bumper.
L26Triggers (버튼으로도 인식됨)Triggers (also recognized as buttons)
R27오른쪽 트리거 단추.Right trigger button.
SHARE_VIEW8System
OPTIONS_MENU9옵션, 메뉴 단추.Options, menu button.
L310Stick Clicks
R311오른쪽 스틱 누름.Right stick click.
DPAD_UP12D-Pad
DPAD_DOWN13방향 패드 아래.D-pad down.
DPAD_LEFT14방향 패드 왼쪽.D-pad left.
DPAD_RIGHT15방향 패드 오른쪽.D-pad right.
HOME_PS16Center
TOUCHPAD17터치패드 누름.Touchpad click.

GamepadKindenum

짝Counterpart: vanilla-engine GamepadKind

게임패드 종류. (단추 안내를 그 패드의 표기로 보일 때 쓴다)

Gamepad type. (used to show button hints in that pad's notation)

이름Name값Value설명Description
xboxxbox엑스박스 패드.Xbox pad.
playstationplaystation플레이스테이션 패드.PlayStation pad.
nintendonintendo닌텐도 패드.Nintendo pad.
otherother그 밖의 패드, 또는 모름.Other pad, or unknown.