sprite_get_width 함수 설명
sprite_get_width 함수는 기본 리소스 스프라이트의 너비를 픽셀 단위로 반환하는 함수입니다. 이 함수는 변형이 적용되지 않은 스프라이트의 너비를 확인할 때 사용됩니다.
문법
sprite_get_width(index);
인수 설명
| 인수 | 타입 | 설명 |
|---|---|---|
| index | 정수 | 너비를 찾고자 하는 스프라이트의 인덱스 |
반환값
- 스프라이트의 너비(픽셀 단위)
예제
다음 코드는 현재 인스턴스의 스프라이트 너비와 기본 스프라이트의 너비를 비교하여, 차이가 있을 경우 x축 스케일을 1로 재설정합니다.
if (sprite_width != sprite_get_width(sprite_index)) {
image_xscale = 1;
}
활용 예제
1. 스프라이트 너비에 따라 위치 조정
var sprite_width = sprite_get_width(sprite_index);
x = x - (sprite_width / 2);
2. 스프라이트 크기에 따라 애니메이션 속도 조정
var width = sprite_get_width(sprite_index);
if (width > 100) {
speed = 5;
} else {
speed = 10;
}
3. 스프라이트 너비에 따른 충돌 처리
if (sprite_get_width(sprite_index) > 50) {
// 큰 스프라이트에 대한 충돌 처리
}
4. 스프라이트 너비를 기반으로 UI 요소 배치
var width = sprite_get_width(sprite_index);
ui_element.x = x + width + 10; // 스프라이트 오른쪽에 UI 요소 배치
5. 스프라이트 너비에 따라 배경 색상 변경
if (sprite_get_width(sprite_index) < 50) {
background_color = c_red;
} else {
background_color = c_green;
}
이와 같이 sprite_get_width 함수는 스프라이트의 너비를 확인하고, 다양한 상황에서 활용할 수 있는 유용한 함수입니다.