JamTutorial - GalanCM/Godot-Jamkit GitHub Wiki
JamTutorial is designed for linear tutorials. It's ideal for creating onscreen prompts, but flexible enough for written tutorials as well.
To begin the tutorial, run the start_tutorial()
function on JamNode. It will then run through the node's direct children, in order, each of which must have a script with a start_tutorial()
function and a next_tutorial
signal. It starts by calling the start_tutorial
function of the first child node, and then waits for next_tutorial
to be emitted. After it receives the signal, JamTutorial will then start the next tutorial. This process will continue until the last child is run.
A simple tutorial could be defined as follows:
extends Node
signal next_tutorial
func start_tutorial():
print("This is a (pointless) tutorial")
emit_signal("next_tutorial")
Say, for example, that you want to create a tutorial node that waits for the player to press a certain key to continue. You could create a Label
node that tells the player what key to press, with an AnimationPlayer
that has an "intro" and an "outro" animation. From that setup, you could use the following script for your tutorial:
extends Label
signal next_tutorial
func _ready():
set_process_input(false) # wait for the intro animation to complete before accepting input
func start_tutorial():
$AnimationPlayer.play("intro")
yield($AnimationPlayer, "animation_finished")
set_process_input(true)
func _input(event):
if event.is_action_pressed("Action"):
$AnimationPlayer.play("outro")
yield($AnimationPlayer, "animation_finished")
emit_signal("next_tutorial")
set_process_input(false) # disable tutorial node when done
Or, you could wait for an event from another node:
...
func start_tutorial():
var player = get_player()
yield(player, "died")
$AnimationPlayer.play("show")
yield(get_tree().create_timer(5), "timeout")
emit_signal("next_tutorial")
...
Note that tutorial nodes will automatically hide()
when the JamTutorial is added to the scene, show()
when before start_tutorial()
is called, and hide()
again after the next_tutorial
signal is received. Any other effects are up the the developer.