device_mouse_raw_x 함수 설명
device_mouse_raw_x
함수는 장치에서 터치된 실제 x 위치를 반환합니다. 이 함수는 게임 메이커의 x 위치가 아니라, 터치된 위치의 실제 장치 정의를 반환하며, 뷰 위치나 스케일링 같은 요소는 무시합니다. 감지할 수 있는 최대 터치 수는 사용 중인 장치와 운영 체제에 따라 다릅니다.
참고: 이 함수는 장치에 따라 다르므로, 원하는 모듈과 장치에서 반환되는 값을 실험해보는 것이 좋습니다.
문법
device_mouse_raw_x(device);
인수
인수 | 유형 | 설명 |
---|---|---|
device | 정수 | 체크할 장치 (0부터 n까지) |
반환값
- x 위치의 원시 값
예제
if (device_mouse_check_button(0, mb_left) && device_mouse_check_button(1, mb_left)) {
x_av = mean(device_mouse_raw_x(0), device_mouse_raw_x(1));
y_av = mean(device_mouse_raw_y(0), device_mouse_raw_y(1));
}
위의 코드는 장치 1과 장치 2가 눌리고 있는지 확인하고, 눌린 지점 간의 x/y 좌표의 평균 위치를 계산합니다.
활용 예제
- 멀티 터치 입력 처리
gml if (device_mouse_check_button(0, mb_left)) { var x_pos = device_mouse_raw_x(0); var y_pos = device_mouse_raw_y(0); // 터치 위치에 따라 오브젝트 이동 instance_create_layer(x_pos, y_pos, "Instances", obj_touch); }
- 터치 위치 기반 UI 조작
gml if (device_mouse_check_button(0, mb_left)) { var x_pos = device_mouse_raw_x(0); var y_pos = device_mouse_raw_y(0); // UI 버튼 클릭 확인 if (point_in_rectangle(x_pos, y_pos, button_x, button_y, button_width, button_height)) { // 버튼 클릭 처리 button_click(); } }
- 다중 터치로 드래그 기능 구현
gml if (device_mouse_check_button(0, mb_left) && device_mouse_check_button(1, mb_left)) { var x1 = device_mouse_raw_x(0); var y1 = device_mouse_raw_y(0); var x2 = device_mouse_raw_x(1); var y2 = device_mouse_raw_y(1); // 두 터치 간의 평균 위치로 오브젝트 이동 var avg_x = (x1 + x2) / 2; var avg_y = (y1 + y2) / 2; instance_position(avg_x, avg_y, obj_drag); }
- 터치 위치 기록
gml if (device_mouse_check_button(0, mb_left)) { var x_pos = device_mouse_raw_x(0); var y_pos = device_mouse_raw_y(0); // 터치 위치를 배열에 저장 array_push(touch_positions, [x_pos, y_pos]); }
- 터치 위치에 따른 애니메이션
gml if (device_mouse_check_button(0, mb_left)) { var x_pos = device_mouse_raw_x(0); var y_pos = device_mouse_raw_y(0); // 터치 위치에 따라 애니메이션 시작 if (distance_to_point(x_pos, y_pos) < threshold) { start_animation(); } }