/// <summary> /// Adds a sprite body modifier that alters some, but not all, of the body. <see cref="ICharacterSprite"/>s /// that do not support dynamic sprites treat this the same as <see cref="ICharacterSprite.SetBody"/>. /// </summary> /// <param name="bodyModifierName">The name of the sprite body modifier.</param> public void AddBodyModifier(string bodyModifierName) { var set = _skelManager.GetSet(bodyModifierName); set = SkeletonAnimation.CreateSmoothedSet(set, _skelAnim.Skeleton); var mod = new SkeletonAnimation(GetTime(), set); _skelAnim.AddModifier(mod); }
/// <summary> /// Sets the Set that describes how the sprite is laid out. /// </summary> /// <param name="setName">The name of the Set.</param> /// <param name="bodySize">The size of the body.</param> public void SetSet(string setName, Vector2 bodySize) { // Check that the set has changed if (setName == _currSkelSet) { return; } _bodySize = bodySize; var newSet = _skelManager.GetSet(setName); if (_skelAnim == null) { _skelAnim = new SkeletonAnimation(GetTime(), newSet); } _skelAnim.ChangeSet(newSet); _currSkelSet = setName; }
/// <summary> /// Adds a SkeletonAnimation modifier to this SkeletonAnimation. /// </summary> /// <param name="modifier">SkeletonAnimation to use as a modifier.</param> /// <param name="loop">If true, the modifier will loop forever until Detach() is called on the /// modifier or RemoveModifiers() is called on the parent.</param> public void AddModifier(SkeletonAnimation modifier, bool loop = false) { if (modifier == null) { Debug.Fail("modifier is null."); return; } // Remove any current modifier if (_mod != null) { _mod.Detach(); } // Attach the modifier to this SkeletonAnimation modifier._parent = this; _mod = modifier; // If not looping, detach once the animation finishes if (!loop) { modifier.Looped += modifier_Looped; } }
/// <summary> /// Handles the Click event of the btnInterpolate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnInterpolate_Click(object sender, EventArgs e) { var result = GetLoadSkeletonDialogResult(_filterFrame); if (result == null || result.Length <= 1) return; var frame1Skeleton = SkeletonLoader.LoadSkeleton(result); var frame1 = new SkeletonFrame(result, frame1Skeleton, 10); result = GetLoadSkeletonDialogResult(_filterFrame); if (result == null || result.Length <= 1) return; var frame2Skeleton = SkeletonLoader.LoadSkeleton(result); var frame2 = new SkeletonFrame(result, frame2Skeleton, 10); var frames = new[] { frame1, frame2 }; var ss = new SkeletonSet(frames); var sa = new SkeletonAnimation(GetTime(), ss); sa.Update(5); LoadFrame(sa.Skeleton); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) return; // Create the engine objects _drawingManager = new DrawingManager(GameScreen.RenderWindow); _camera = new Camera2D(new Vector2(GameScreen.Width, GameScreen.Height)) { KeepInMap = false }; _content = ContentManager.Create(); _font = _content.LoadFont("Font/Arial", 14, ContentLevel.GameScreen); GrhInfo.Load(ContentPaths.Dev, _content); // Create the skeleton-related objects _skeleton = new Skeleton(); var frameSkeleton = new Skeleton(SkeletonLoader.StandingSkeletonName, ContentPaths.Dev); var frame = new SkeletonFrame(SkeletonLoader.StandingSkeletonName, frameSkeleton); _skeletonAnim = new SkeletonAnimation(GetTime(), frame); LoadFrame(Skeleton.GetFilePath(SkeletonLoader.StandingSkeletonName, ContentPaths.Dev)); LoadAnim(SkeletonSet.GetFilePath(SkeletonLoader.WalkingSkeletonSetName, ContentPaths.Dev)); LoadBody(SkeletonBodyInfo.GetFilePath(SkeletonLoader.BasicSkeletonBodyName, ContentPaths.Dev)); LoadSkelSets(ContentPaths.Build.Grhs + "\\Character\\Skeletons"); _watch.Start(); ResetCamera(); GameScreen.MouseWheel += GameScreen_MouseWheel; }
/// <summary> /// Sets the Set that describes how the sprite is laid out. /// </summary> /// <param name="setName">The name of the Set.</param> /// <param name="bodySize">The size of the body.</param> public void SetSet(string setName, Vector2 bodySize) { // Check that the set has changed if (setName == _currSkelSet) return; _bodySize = bodySize; var newSet = _skelManager.GetSet(setName); if (_skelAnim == null) _skelAnim = new SkeletonAnimation(GetTime(), newSet); _skelAnim.ChangeSet(newSet); _currSkelSet = setName; }
/// <summary> /// If the <see cref="SkeletonAnimation"/> is used as a modifier, this will detach it from its parent. /// </summary> public void Detach() { if (_parent != null) { _parent._mod = null; _parent = null; } }
/// <summary> /// Adds a SkeletonAnimation modifier to this SkeletonAnimation. /// </summary> /// <param name="modifier">SkeletonAnimation to use as a modifier.</param> /// <param name="loop">If true, the modifier will loop forever until Detach() is called on the /// modifier or RemoveModifiers() is called on the parent.</param> public void AddModifier(SkeletonAnimation modifier, bool loop = false) { if (modifier == null) { Debug.Fail("modifier is null."); return; } // Remove any current modifier if (_mod != null) _mod.Detach(); // Attach the modifier to this SkeletonAnimation modifier._parent = this; _mod = modifier; // If not looping, detach once the animation finishes if (!loop) { modifier.Looped -= modifier_Looped; modifier.Looped += modifier_Looped; } }