게임메이커에서 텍스트창에 텍스트를 출력해 보겠다.
// Create
text_queue=ds_queue_create();
ds_queue_enqueue(text_queue, "Hello!", "This is test message.", "I'm not NPC :(");
text=ds_queue_dequeue(text_queue);
index=0;
delay=5;
alarm[0]=delay;
// Alarm 0
if (index < string_length(text))
{
index++;
alarm[0]=delay;
}
// Draw
// Draw GUI
draw_self();
draw_set_valign(fa_center);
draw_set_halign(fa_middle);
draw_text(x, y,string_copy(text, 1, index));
// Key Press - Z
if (index >= string_length(text))
{
text=ds_queue_dequeue(text_queue);
index=0;
alarm[0]=delay;
}
- ds_queue_create() : 큐 생성
- ds_queue_enqueue(id, value,...) : 큐에 값 넣기 (id : 큐 이름, value : 큐에 넣을 값)
- ds_queue_dequeue(id) : 큐에 있는 값을 가져오고 큐에서 그 값을 삭제
- draw_self() : 인스턴스에 할당된 스프라이트를 그림
각 변수들의 기능을 알아보겠다.
- text_queue : 출력할 문자열을 저장할 큐
- text : 큐에 저장되어 있는 문자열을 출력하기 위해 큐에 있는 문자열을 가져오고 저장하는 역할
- index : 현재 문자열의 위치를 나타냄
- delay : 텍스트가 출력될 간격
각 이벤트의 기능을 알아보겠다.
- Create : 변수 초기값 설정
- Alarm 0 : index 값 증가
- Draw : 룸에 스프라이트 중복 표시 방지
- Draw GUI : 텍스트박스, 문자열 출력
- Key Press - Space : 다음 문자열 출력