sprite_prefetch 함수 설명
sprite_prefetch 함수는 주어진 스프라이트와 함께 텍스처 페이지를 미리 로드(텍스처 메모리에 배치)하는 데 사용됩니다. 이 함수는 스프라이트 자산을 생성할 때 정의된 스프라이트 인덱스를 입력으로 받으며, 해당 스프라이트가 있는 텍스처 페이지가 메모리에 로드됩니다.
주의: 이 함수는 선택한 리소스에 대해 미리 로드가 지원되지 않거나 대상 플랫폼이 HTML5인 경우 -1을 반환하며, 모든 것이 정상적으로 작동하면 0을 반환합니다.
문법
sprite_prefetch(ind)
인수
| 인수 | 유형 | 설명 |
|---|---|---|
| ind | Sprite Asset | 가져올 스프라이트 인덱스 |
반환값
| 반환값 | 설명 |
|---|---|
| Real | -1 또는 0 |
예제
sprite_prefetch(spr_Player_Aura);
위 코드는 참조된 스프라이트를 텍스처 메모리에 로드하여 사용할 준비를 합니다.
활용 예제
예제 1: 게임 시작 시 스프라이트 미리 로드하기
// 게임 시작 시 필요한 스프라이트 미리 로드
sprite_prefetch(spr_Player);
sprite_prefetch(spr_Enemy);
sprite_prefetch(spr_Background);
예제 2: 특정 이벤트 발생 시 스프라이트 미리 로드하기
// 플레이어가 특정 지역에 도착했을 때 스프라이트 미리 로드
if (player_in_special_area) {
sprite_prefetch(spr_SpecialEffect);
}
예제 3: 여러 스프라이트를 동시에 미리 로드하기
// 여러 스프라이트를 미리 로드하는 함수
function prefetch_sprites() {
sprite_prefetch(spr_Explosion);
sprite_prefetch(spr_PowerUp);
sprite_prefetch(spr_Item);
}
예제 4: 스프라이트 미리 로드 실패 처리
// 스프라이트 미리 로드 실패 시 처리
var result = sprite_prefetch(spr_Player_Aura);
if (result == -1) {
show_error("스프라이트 미리 로드 실패!", true);
}
이 문서에서는 sprite_prefetch 함수의 사용법과 다양한 활용 예제를 설명했습니다.