입력

Pyxen은 키보드, 터치, 마우스, 게임패드 입력을 지원합니다. 모든 입력은 input 모듈을 통해 읽히며, update()가 실행되기 전 매 프레임 업데이트됩니다.

키보드

input.keyboard에서 이름으로 키에 접근합니다:

if input.keyboard.right.down:
    player.x += 2

if input.keyboard.space.pressed:
    jump()

모든 키는 같은 속성을 노출합니다:

속성의미
down이 프레임에 눌려 있음
pressed이 프레임에 막 눌림 (한 프레임만 true)
released이 프레임에 막 놓임 (한 프레임만 true)
value아날로그 값 (키의 경우 0.0 또는 1.0)

일반적인 키 이름: left, right, up, down, space, enter, escape, az, 09.

터치

iPad에서 터치 입력은 input.touches를 통해 들어옵니다 — 활성 터치 포인트 목록:

for touch in input.touches:
    if touch.started:
        spawn_particle(touch.x, touch.y)

각 터치에는 다음이 있습니다:

속성의미
x, y게임 좌표에서의 위치
dx, dy이전 프레임 이후의 이동
pressure터치 압력 (지원되는 경우)
down현재 터치 중
started이 프레임에 터치 시작
ended이 프레임에 터치 종료

마우스

마우스 입력은 Mac과 마우스 또는 트랙패드가 연결된 iPad에서 작동합니다:

if input.mouse.buttons.left.pressed:
    shoot(input.mouse.x, input.mouse.y)

마우스는 다음을 노출합니다:

게임패드

Pyxen은 최대 4개의 게임패드를 지원합니다. input.gamepads를 통해 접근합니다:

pad = input.gamepads[0]
if pad.connected:
    player.x += pad.left_stick.x * 2
    if pad.buttons.a.pressed:
        jump()

각 게임패드에는 다음이 있습니다:

여러 입력 설계

Pyxen 게임은 터치가 있는 iPad, 키보드가 있는 iPad, 또는 마우스와 키보드가 있는 Mac에서 실행될 수 있습니다. 좋은 방법은 여러 입력 소스를 확인하는 것입니다:

def update():
    dx = 0
    if input.keyboard.right.down:
        dx = 2
    elif input.keyboard.left.down:
        dx = -2

    pad = input.gamepads[0]
    if pad.connected:
        dx = pad.left_stick.x * 2

    player.x += dx

전체 API는 입력 레퍼런스를 참조하세요.