C# Tween Example

For this one I was stuck for a while trying to get the tween to do a callback and not just immediately return when completing a level. Here is what my CompleteLevel and CrashSequence look like in C# in godot 4.2.2

	private void CompleteLevel(String nextLevelFile)
	{
		GD.Print("Level Complete");
		
		// stop processing while transitioning
		SetProcess(false);
		isTransitioning = true;
		
		// start the tween to wait 1 second before loading the next level
		var tween = CreateTween();
		tween.TweenCallback(Callable.From(() => GetTree().ChangeSceneToFile(nextLevelFile))).SetDelay(1.0);
	}
	
	private void CrashSequence()
	{
		GD.Print("KABOOM");
		
		// stop processing while transitioning
		SetProcess(false);
		isTransitioning = true;
		
		// start the tween to wait 1 second before reloading the current level
		var tween = CreateTween();
		tween.TweenCallback(Callable.From(GetTree().ReloadCurrentScene)).SetDelay(1.0);
	}

Privacy & Terms