스프라이트 경계 상자 모드 설정
sprite_set_bbox_mode 함수는 스프라이트의 경계 상자 모드를 설정하는 데 사용됩니다. 이 함수는 스프라이트 인덱스와 사용할 모드를 인자로 받습니다. 모드는 다음 상수 중 하나여야 합니다.
주의사항
이 함수는 스프라이트 자산에 영향을 미치며, 이후 이 스프라이트를 사용하는 모든 인스턴스는 동일한 경계 상자 모드를 갖게 됩니다.
문법
sprite_set_bbox_mode(ind, mode);
인자 설명
| 인자 | 타입 | 설명 |
|---|---|---|
| ind | Sprite Asset | 모드를 변경할 스프라이트의 인덱스 |
| mode | Bounding Box Mode Constant | 설정할 모드 (상수) |
반환값
N/A
예제
if (sprite_get_bbox_mode(sprite_index) != bboxmode_automatic) {
sprite_set_bbox_mode(sprite_index, bboxmode_automatic);
}
위 코드는 현재 스프라이트의 경계 상자 모드를 확인하고, 만약 자동 모드가 아닐 경우 자동 모드로 설정합니다.
활용 예제
예제 1: 스프라이트 모드 변경
// 스프라이트의 경계 상자 모드를 수동으로 설정
sprite_set_bbox_mode(sprite_index, bboxmode_manual);
예제 2: 모든 스프라이트에 대해 경계 상자 모드 설정
// 모든 스프라이트에 대해 자동 모드로 설정
for (var i = 0; i < sprite_get_number(); i++) {
sprite_set_bbox_mode(i, bboxmode_automatic);
}
예제 3: 특정 조건에 따라 모드 변경
// 특정 조건이 충족되면 경계 상자 모드 변경
if (some_condition) {
sprite_set_bbox_mode(sprite_index, bboxmode_precise);
}
예제 4: 스프라이트 인스턴스 생성 시 모드 설정
// 새로운 스프라이트 인스턴스를 생성하면서 경계 상자 모드 설정
var new_instance = instance_create_layer(x, y, "Instances", obj_sprite);
sprite_set_bbox_mode(new_instance.sprite_index, bboxmode_automatic);
이와 같이 sprite_set_bbox_mode 함수를 활용하여 스프라이트의 경계 상자 모드를 유연하게 설정할 수 있습니다.