/// <summary> /// Updates the parent <see cref="SkeletonAnimation"/> that this modifier modifies. /// </summary> /// <param name="src">Source root <see cref="SkeletonNode"/>.</param> /// <param name="dest">Destination root <see cref="SkeletonNode"/>.</param> static void RecursiveUpdateParent(SkeletonNode src, SkeletonNode dest) { // Update modified values if (src.IsModifier && dest.Parent != null) { dest.SetAngle(src.GetAngle()); } // Update the child nodes (if there is any) for (var i = 0; i < src.internalNodes.Count; i++) { RecursiveUpdateParent(src.internalNodes[i], dest.internalNodes[i]); } }
/// <summary> /// Draws the <see cref="SkeletonBodyItem"/>. /// </summary> /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param> /// <param name="position">Position to draw at.</param> /// <param name="scale">Amount to scale the Grh in percent (1.0f for no scaling).</param> /// <param name="color">The color.</param> /// <param name="effect">SpriteEffects to use when drawing.</param> internal void Draw(ISpriteBatch sb, Vector2 position, float scale, Color color, SpriteEffects effect) { // Validate if (Source == null) { return; } // Find the effect Vector2 m; switch (effect) { case SpriteEffects.FlipHorizontally: m = new Vector2(-1, 1); break; case SpriteEffects.FlipVertically: m = new Vector2(1, -1); break; default: m = new Vector2(1, 1); break; } // Calculate the angle float angle; if (Dest == null) { angle = 0.0f; } else { angle = SkeletonNode.GetAngle(Source.Position * m, Dest.Position * m) - MathHelper.PiOver2; } // Draw var v = Source.Position + ItemInfo.Offset; Grh.Draw(sb, (v * m) + position, color, effect, angle, ItemInfo.Origin, scale); }
/// <summary> /// Recursively updates all the children of a node. /// </summary> /// <param name="srcA">Source skeleton node for the current frame.</param> /// <param name="srcB">Source skeleton node for the next frame.</param> /// <param name="srcP">Parent skeleton node (use null if theres no parent).</param> /// <param name="dest">Destination skeleton node to have the two sources applied to.</param> /// <param name="framePercent">A value between 0.0 and 1.0 stating how far along the animation is /// from the current frame.</param> void RecursiveUpdate(SkeletonNode srcA, SkeletonNode srcB, SkeletonNode srcP, SkeletonNode dest, float framePercent) { // Set the position Vector2 vA; Vector2 vB; if (_scale == 1.0f) { vA = srcA.Position; vB = srcB.Position; } else { vA = srcA.Position * _scale; vB = srcB.Position * _scale; } dest.Position = Vector2.Lerp(vA, vB, framePercent); // Check if the node is part of a modifier animation if (srcP == null) { // Set the length dest.SetLength(srcA.GetLength() * _scale); } else { // This is a modifier so check for inheriting node values dest.SetLength(srcP.GetLength()); if (!srcP.IsModifier && srcP.Parent != null) { dest.SetAngle(srcP.GetAngle()); } } // Update the child nodes (if there is any) for (var i = 0; i < srcA.internalNodes.Count; i++) { var nextSrcP = (srcP == null ? null : srcP.internalNodes[i]); RecursiveUpdate(srcA.internalNodes[i], srcB.internalNodes[i], nextSrcP, dest.internalNodes[i], framePercent); } }
/// <summary> /// Updates the parent <see cref="SkeletonAnimation"/> that this modifier modifies. /// </summary> /// <param name="src">Source root <see cref="SkeletonNode"/>.</param> /// <param name="dest">Destination root <see cref="SkeletonNode"/>.</param> static void RecursiveUpdateParent(SkeletonNode src, SkeletonNode dest) { // Update modified values if (src.IsModifier && dest.Parent != null) dest.SetAngle(src.GetAngle()); // Update the child nodes (if there is any) for (var i = 0; i < src.internalNodes.Count; i++) { RecursiveUpdateParent(src.internalNodes[i], dest.internalNodes[i]); } }
/// <summary> /// Recursively updates all the children of a node. /// </summary> /// <param name="srcA">Source skeleton node for the current frame.</param> /// <param name="srcB">Source skeleton node for the next frame.</param> /// <param name="srcP">Parent skeleton node (use null if theres no parent).</param> /// <param name="dest">Destination skeleton node to have the two sources applied to.</param> /// <param name="framePercent">A value between 0.0 and 1.0 stating how far along the animation is /// from the current frame.</param> void RecursiveUpdate(SkeletonNode srcA, SkeletonNode srcB, SkeletonNode srcP, SkeletonNode dest, float framePercent) { // Set the position Vector2 vA; Vector2 vB; if (_scale == 1.0f) { vA = srcA.Position; vB = srcB.Position; } else { vA = srcA.Position * _scale; vB = srcB.Position * _scale; } dest.Position = Vector2.Lerp(vA, vB, framePercent); // Check if the node is part of a modifier animation if (srcP == null) { // Set the length dest.SetLength(srcA.GetLength() * _scale); } else { // This is a modifier so check for inheriting node values dest.SetLength(srcP.GetLength()); if (!srcP.IsModifier && srcP.Parent != null) dest.SetAngle(srcP.GetAngle()); } // Update the child nodes (if there is any) for (var i = 0; i < srcA.internalNodes.Count; i++) { var nextSrcP = (srcP == null ? null : srcP.internalNodes[i]); RecursiveUpdate(srcA.internalNodes[i], srcB.internalNodes[i], nextSrcP, dest.internalNodes[i], framePercent); } }