Time Source 시작하기
이 문서는 time_source_start
함수에 대해 설명합니다. 이 함수는 주어진 시간 소스를 시작하고, 그 상태를 time_source_state_active
로 변경합니다. 지정된 시간 소스는 새로 생성된 것일 수도 있고, 일시 중지되었거나, 중지되었거나, 반복 없이 만료된 것일 수 있습니다. 이 함수는 주어진 시간 소스를 "소프트 리셋"하여 만료 시간과 남은 반복 횟수를 구성된 값으로 초기화합니다.
문법
time_source_start(id);
인수 설명
인수 | 유형 | 설명 |
---|---|---|
id | Time Source ID | 시작할 시간 소스의 ID |
반환 값
- N/A
예제
다음은 시간 소스를 시작하는 예제입니다.
var _my_method = function(){
instance_destroy();
}
var _time_source = time_source_create(time_source_game, 300, time_source_units_frames, _my_method);
time_source_start(_time_source);
이 예제에서는 인스턴스가 300 프레임 후에 스스로 파괴되도록 설정합니다. 코드는 먼저 instance_destroy()
를 호출하는 메서드를 생성합니다. 그런 다음 게임 시간 소스를 상속받아 시간 소스를 생성하고, 주기를 300 프레임으로 설정합니다. 마지막으로 시간 소스를 시작합니다.
활용 및 응용 예제
- 게임 이벤트 타이머
gml var _event_method = function(){ show_message("이벤트 발생!"); } var _event_timer = time_source_create(time_source_game, 600, time_source_units_frames, _event_method); time_source_start(_event_timer);
- 스코어 업데이트
gml var _score_update_method = function(){ score += 10; } var _score_timer = time_source_create(time_source_game, 120, time_source_units_frames, _score_update_method); time_source_start(_score_timer);
- 애니메이션 재생
gml var _animation_method = function(){ sprite_index = spr_animation; } var _animation_timer = time_source_create(time_source_game, 90, time_source_units_frames, _animation_method); time_source_start(_animation_timer);
- 게임 종료
gml var _game_over_method = function(){ game_over = true; } var _game_over_timer = time_source_create(time_source_game, 300, time_source_units_frames, _game_over_method); time_source_start(_game_over_timer);
- 아이템 생성
gml var _item_spawn_method = function(){ instance_create_layer(x, y, "Instances", obj_item); } var _item_spawn_timer = time_source_create(time_source_game, 180, time_source_units_frames, _item_spawn_method); time_source_start(_item_spawn_timer);