private void FinishFormChange(PlayerForm form) { if (TransitionSprite.IsInsideTree()) { RemoveChild(TransitionSprite); } string nodeName = "Player" + PlayerNumber; NodePath nodePath = new NodePath(nodeName); Node formScene = CurrentScene.Instance(); formScene.Name = nodeName; AddChild(formScene); Player newPlayerScript = GetNode <Player>(nodePath); FormChangeDelayTimer = 0; IsChangingForm = false; string frameCacheKey = SpriteFolderName + "/" + CurrentForm.ToString(); newPlayerScript.SetupPlayer(PlayerInputManager, PreviousTransform, PreviousVelocity, FrameCache[frameCacheKey], PreviousSpriteFlipped); CurrentPlayer = newPlayerScript; }
private void ChangeForm(PlayerForm form, bool instant = false) { IsChangingForm = true; CurrentForm = form; GD.Print("Changing form to " + form.ToString()); if (!SceneCache.ContainsKey(CurrentForm)) { SceneCache.Add(CurrentForm, GD.Load <PackedScene>(Constants.FilePath.PLAYER_FORM_SCENES + CurrentForm.ToString() + ".tscn")); } CurrentScene = SceneCache[CurrentForm]; string frameCacheKey = SpriteFolderName + "/" + CurrentForm.ToString(); if (!FrameCache.ContainsKey(frameCacheKey)) { FrameCache.Add(frameCacheKey, GD.Load <SpriteFrames>(Constants.FilePath.PLAYER_FRAMES + SpriteFolderName + "/" + CurrentForm.ToString() + ".tres")); } CurrentFrames = FrameCache[frameCacheKey]; Player oldFormScene = GetChildCount() > 0 ? GetChildOrNull <Player>(0) : null; oldFormScene?.SetName("QueuedForDeletion"); if (oldFormScene != null) { PreviousTransform = oldFormScene.GetGlobalTransform(); PreviousVelocity = oldFormScene.Velocity; AnimatedSprite3D sprite = GetNode <AnimatedSprite3D>(new NodePath("QueuedForDeletion/PlayerSprite")); PreviousSpriteFlipped = sprite.IsFlippedH(); if (!instant) { //Create blinking state transition TransitionFrames.Clear("Transition"); TransitionFrames.AddFrame("Transition", sprite.Frames.GetFrame(Player.PlayerAnimation.IDLE, 0), 0); TransitionFrames.AddFrame("Transition", CurrentFrames.GetFrame(Player.PlayerAnimation.IDLE, 0), 1); TransitionSprite.SetGlobalTransform(sprite.GetGlobalTransform().Translated(-Transform.origin)); TransitionSprite.SetFlipH(sprite.FlipH); TransitionSprite.SetPixelSize(sprite.GetPixelSize()); TransitionSprite.Play("Transition"); } oldFormScene.SetProcess(false); oldFormScene.SetPhysicsProcess(false); oldFormScene.QueueFree(); } if (instant) { FinishFormChange(form); return; } AddChild(TransitionSprite); }