public SpriterSubstituteEntity(string replacedPartFilename, CustomSpriterAnimator referenceAnimator, CustomSpriterAnimator substituteAnimator) { _replacedPartFilename = replacedPartFilename; _referenceAnimator = referenceAnimator; SubstituteAnimator = substituteAnimator; _replacedSpriterFile = SpriterUtils.GetSpriterFileStaticData(_replacedPartFilename, SubstituteAnimator); _replacedSpriterFileHalfSize = new Size2(_replacedSpriterFile.Width / 2, _replacedSpriterFile.Height / 2); referenceAnimator.AddHiddenTexture(replacedPartFilename); }
public static Vector2 GetWorldPosition(string spriterPartFilename, MonoGameAnimator animator, Vector2?optionalLocalPosition = null) { var vertex = optionalLocalPosition.HasValue ? optionalLocalPosition.Value : Vector2.Zero; var worldPosition = animator.Position + vertex; if (animator.FrameData != null) { // Compute translation int folderId = 0; var spriterPartFile = SpriterUtils.GetSpriterFile(spriterPartFilename, animator, out folderId); var spriteData = animator.FrameData.SpriteData.Find((so) => so.FileId == spriterPartFile.Id); var animationOffset = new Vector2(spriteData.X, -spriteData.Y); var scale = new Vector2(spriteData.ScaleX, spriteData.ScaleY); var realPivotPosition = new Vector2(1 - spriteData.PivotX, 1 - spriteData.PivotY); vertex *= scale; var spriteCenter = new Vector2( spriterPartFile.Width * realPivotPosition.X, spriterPartFile.Height * realPivotPosition.Y ); var worldTopLeftCornerPosition = animator.Position - (spriteCenter * scale); worldPosition = worldTopLeftCornerPosition + vertex + animationOffset; // Compute rotation var pivot = new Vector2( (spriterPartFile.Width * realPivotPosition.X) + spriteData.X, (spriterPartFile.Height * realPivotPosition.Y) - spriteData.Y ); var origin = animator.Position + pivot - spriteCenter; var rotation = -spriteData.Angle; rotation = MathHelper.WrapAngle(MathHelper.ToRadians(rotation)); // Take the animation angle into account worldPosition = MathExtension.RotatePoint( worldPosition, rotation, origin ); // Take the global angle into account worldPosition = MathExtension.RotatePoint( worldPosition, animator.Rotation, animator.Position ); } return(worldPosition); }
public void Synchronize() { // Synchronize current GUI button animator with the related dummy element from the Spriter file var spriterDummyData = SpriterUtils.GetSpriterFileData(_replacedPartFilename, _referenceAnimator); if (spriterDummyData != null) { var dummyPosition = new Vector2(spriterDummyData.X, -spriterDummyData.Y); var dummyScale = new Vector2(spriterDummyData.ScaleX, spriterDummyData.ScaleY); SubstituteAnimator.Position = _referenceAnimator.Position + dummyPosition; SubstituteAnimator.Rotation = -MathHelper.ToRadians(spriterDummyData.Angle); SubstituteAnimator.Scale = dummyScale; SubstituteAnimator.Color = new Color(SubstituteAnimator.Color, spriterDummyData.Alpha); } }
public void Synchronize() { // Synchronize current GUI button animator with the related dummy element from the Spriter file var spriterDummyData = SpriterUtils.GetSpriterFileData(_replacedPartFilename, _referenceAnimator, _timelineName); if (spriterDummyData != null && !_firstFrame) { var dummyPosition = new Vector2(spriterDummyData.X, -spriterDummyData.Y); var dummyScale = new Vector2(spriterDummyData.ScaleX, spriterDummyData.ScaleY); SubstituteAnimator.Position = _referenceAnimator.Position + dummyPosition; SubstituteAnimator.Rotation = -MathHelper.ToRadians(spriterDummyData.Angle); SubstituteAnimator.Scale = dummyScale; SubstituteAnimator.Color = new Color(SubstituteAnimator.Color, spriterDummyData.Alpha); } else if (_firstFrame) { // Workaround to avoid desync on the first frame SubstituteAnimator.Scale = Vector2.Zero; } }