protected void UpdateFrom(VisibleTimeline Other, AnimationClass.AnimationLayer ActiveLayer) { base.UpdateFrom(Other, ActiveLayer); NextEventKeyFrame = Other.NextEventKeyFrame; if (NextEventKeyFrame >= 0 && Other.Count > 0) { NextEvent = DicAnimationKeyFrame[NextEventKeyFrame]; } else { NextEvent = null; } _Position = Other._Position; PositionOld = Other.PositionOld; EventKeyFrameOld = Other.EventKeyFrameOld; Origin = Other.Origin; SpawnFrame = Other.SpawnFrame; DeathFrame = Other.DeathFrame; DrawingDepth = Other.DrawingDepth; DrawingDepthOld = Other.DrawingDepthOld; ScaleFactor = Other.ScaleFactor; ScaleFactorOld = Other.ScaleFactorOld; Angle = Other.Angle; AngleOld = Other.AngleOld; Alpha = Other.Alpha; AlphaOld = Other.AlphaOld; }
public VisibleAnimationObjectKeyFrame Copy(AnimationClass.AnimationLayer ActiveLayer, int NextKeyFrame) { VisibleAnimationObjectKeyFrame NewKeyFrame = CopyAsVisibleAnimationObjectKeyFrame(ActiveLayer); NewKeyFrame.NextKeyFrame = NextKeyFrame; return(NewKeyFrame); }
public SpriteSheetTimeline(BinaryReader BR, ContentManager Content) : base(BR, TimelineType) { SpriteSheetName = BR.ReadString(); SourceRectangle = new Rectangle(); SourceRectangle.X = BR.ReadInt32(); SourceRectangle.Y = BR.ReadInt32(); SourceRectangle.Width = BR.ReadInt32(); SourceRectangle.Height = BR.ReadInt32(); int DicAnimationSpriteKeyFrameCount = BR.ReadInt32(); for (int E = 0; E < DicAnimationSpriteKeyFrameCount; E++) { int Key = BR.ReadInt32(); VisibleAnimationObjectKeyFrame NewAnimatedBitmapKeyFrame = new VisibleAnimationObjectKeyFrame(BR); DicAnimationKeyFrame.Add(Key, NewAnimatedBitmapKeyFrame); } if (Content != null) { SpriteSheet = Content.Load <Texture2D>("Animations/Sprite Sheets/" + SpriteSheetName); } Origin = new Point(Width / 2, Height / 2); }
public override void MoveTimeline(int Difference) { if (NextEventKeyFrame >= 0)//If there is a next key frame, update it. { NextEventKeyFrame += Difference; } //Remove first to avoid duplicate error Dictionary <int, VisibleAnimationObjectKeyFrame> ListRemovedKeyFrame = new Dictionary <int, VisibleAnimationObjectKeyFrame>(); foreach (int KeyFrame in Keys) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = DicAnimationKeyFrame[KeyFrame]; ListRemovedKeyFrame.Add(KeyFrame, ActiveKeyFrame); Remove(KeyFrame); } foreach (KeyValuePair <int, VisibleAnimationObjectKeyFrame> ActiveKeyFrame in ListRemovedKeyFrame) { if (ActiveKeyFrame.Value.NextKeyFrame >= 0)//If there is a next key frame, update it. { ActiveKeyFrame.Value.NextKeyFrame += Difference; } Add(ActiveKeyFrame.Key + Difference, ActiveKeyFrame.Value); } //Replace the old Tag. SpawnFrame += Difference; DeathFrame += Difference;//Changing the deathframe will automatically destroy keyframes so only change it after the movement. }
public ParticleEmitterTimeline(BinaryReader BR, ContentManager Content) : base(BR, TimelineType) { Matrix view = Matrix.Identity; Matrix Projection = Matrix.CreateOrthographicOffCenter(0, 800, 600, 0, 0, 1); Matrix HalfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); Projection = view * (HalfPixelOffset * Projection); Particle3DSample.ParticleSettings ParticleSettings = new Particle3DSample.ParticleSettings(); ParticleSettings.TextureName = BR.ReadString(); ParticleSettings.MaxParticles = 20000; ParticleSettings.MinScale = new Vector2(1, 1); ParticleSettings.DurationInSeconds = 1d; ParticleSettings.Gravity = new Vector2(0, 0); ParticleSettings.NumberOfImages = 16; ParticleSettings.BlendState = BlendState.AlphaBlend; ParticleSettings.StartingAlpha = 0.7f; ParticleSettings.EndAlpha = 0.1f; _SpawnOffset = new Vector2(BR.ReadSingle(), BR.ReadSingle()); _SpawnOffsetRandom = new Vector2(BR.ReadSingle(), BR.ReadSingle()); SpawnSpeed = new Vector2(BR.ReadSingle(), BR.ReadSingle()); SpawnSpeedRandom = new Vector2(BR.ReadSingle(), BR.ReadSingle()); ParticlesPerSeconds = BR.ReadDouble(); ParticleSettings.DurationInSeconds = BR.ReadSingle(); float SpeedMultiplier = BR.ReadSingle(); ParticleSettings.NumberOfImages = BR.ReadInt32(); ParticleSettings.Gravity = new Vector2(BR.ReadSingle(), BR.ReadSingle()); Vector2 Size = new Vector2(BR.ReadSingle(), BR.ReadSingle()); ParticleSettings.MinScale = new Vector2(BR.ReadSingle(), BR.ReadSingle()); ParticleSettings.StartingAlpha = BR.ReadSingle(); ParticleSettings.EndAlpha = BR.ReadSingle(); _ParticleBlendState = (ParticleBlendStates)BR.ReadByte(); TimeBetweenEachParticle = 1 / ParticlesPerSeconds; ParticleSystem = new Particle3DSample.ParticleSystem(ParticleSettings); ParticleSystem.LoadContent(Content, GameScreen.GraphicsDevice, Projection); this.SpeedMultiplier = SpeedMultiplier; this.Size = Size; UpdateSize(); int DicAnimationSpriteKeyFrameCount = BR.ReadInt32(); for (int E = 0; E < DicAnimationSpriteKeyFrameCount; E++) { int Key = BR.ReadInt32(); VisibleAnimationObjectKeyFrame NewAnimatedBitmapKeyFrame = new VisibleAnimationObjectKeyFrame(BR); DicAnimationKeyFrame.Add(Key, NewAnimatedBitmapKeyFrame); } Origin = new Point(Width / 2, Height / 2); }
public virtual bool MouseDownExtra(int RealX, int RealY) { if (Count > 1) { int Index = SpawnFrame; while (Index >= 0) { if (DicAnimationKeyFrame[Index].NextKeyFrame >= 0) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = (VisibleAnimationObjectKeyFrame)Get(Index); for (int N = 0; N < ActiveKeyFrame.ListSpecialEffectNode.Count; N++) { int KeyFrameX = (int)ActiveKeyFrame.ListSpecialEffectNode[N].X - 2; int KeyFrameY = (int)ActiveKeyFrame.ListSpecialEffectNode[N].Y - 2; if (RealX >= KeyFrameX && RealX < KeyFrameX + 5 && RealY >= KeyFrameY && RealY < KeyFrameY + 5) { return(true); } } } Index = DicAnimationKeyFrame[Index].NextKeyFrame; } } return(false); }
public virtual void MouseMoveExtra(int KeyFrame, int RealX, int RealY, int MouseChangeX, int MouseChangeY) { if (Count > 1) { int Index = SpawnFrame; while (Index >= 0) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = DicAnimationKeyFrame[Index]; if (ActiveKeyFrame.NextKeyFrame >= 0) { for (int N = 0; N < ActiveKeyFrame.ListSpecialEffectNode.Count; N++) { int KeyFrameX = (int)ActiveKeyFrame.ListSpecialEffectNode[N].X - 2; int KeyFrameY = (int)ActiveKeyFrame.ListSpecialEffectNode[N].Y - 2; if (RealX >= KeyFrameX && RealX < KeyFrameX + 5 && RealY >= KeyFrameY && RealY < KeyFrameY + 5) { ActiveKeyFrame.ListSpecialEffectNode[N] = new Vector2(ActiveKeyFrame.ListSpecialEffectNode[N].X + MouseChangeX, ActiveKeyFrame.ListSpecialEffectNode[N].Y + MouseChangeY); break; } } } Index = DicAnimationKeyFrame[Index].NextKeyFrame; } } }
public override bool TryGetValue(int Key, out AnimationObjectKeyFrame Value) { VisibleAnimationObjectKeyFrame OutVisibleAnimationObjectKeyFrame = null; bool ReturnValue = DicAnimationKeyFrame.TryGetValue(Key, out OutVisibleAnimationObjectKeyFrame); Value = OutVisibleAnimationObjectKeyFrame; return(ReturnValue); }
protected virtual VisibleAnimationObjectKeyFrame CopyAsVisibleAnimationObjectKeyFrame(AnimationClass.AnimationLayer ActiveLayer) { VisibleAnimationObjectKeyFrame NewVisibleAnimationObjectKeyFrame = new VisibleAnimationObjectKeyFrame(); NewVisibleAnimationObjectKeyFrame.UpdateFrom(this); return(NewVisibleAnimationObjectKeyFrame); }
public VisibleTimeline(string TimelineEventType, string Name) : base(TimelineEventType, Name) { DicAnimationKeyFrame = new Dictionary <int, VisibleAnimationObjectKeyFrame>(); CanDelete = true; NextEvent = null; NextEventKeyFrame = -1; GroupIndex = -1; }
public VisibleTimeline(BinaryReader BR, string TimelineEventType) : base(BR, TimelineEventType) { _SpawnFrame = BR.ReadInt32(); _DeathFrame = BR.ReadInt32(); DicAnimationKeyFrame = new Dictionary <int, VisibleAnimationObjectKeyFrame>(); CanDelete = true; NextEvent = null; NextEventKeyFrame = -1; GroupIndex = -1; }
protected void OnNewKeyFrameAnimationSprite(VisibleAnimationObjectKeyFrame ActiveKeyFrame) { Position = ActiveKeyFrame.Position; ScaleFactor = ActiveKeyFrame.ScaleFactor; Angle = ActiveKeyFrame.AngleInRad; Alpha = ActiveKeyFrame.Alpha; DrawingDepth = ActiveKeyFrame.DrawingDepth; PositionOld = ActiveKeyFrame.Position; ScaleFactorOld = ActiveKeyFrame.ScaleFactor; AngleOld = ActiveKeyFrame.AngleInRad; AlphaOld = ActiveKeyFrame.Alpha; DrawingDepthOld = ActiveKeyFrame.DrawingDepth; ActiveKeyFrame.IsUsed = true; }
public AnimationOriginTimeline(BinaryReader BR) : base(BR, TimelineType) { Origin = new Point(BR.ReadInt32(), BR.ReadInt32()); int DicAnimationSpriteKeyFrameCount = BR.ReadInt32(); for (int E = 0; E < DicAnimationSpriteKeyFrameCount; E++) { int Key = BR.ReadInt32(); VisibleAnimationObjectKeyFrame NewAnimatedBitmapKeyFrame = new VisibleAnimationObjectKeyFrame(BR); DicAnimationKeyFrame.Add(Key, NewAnimatedBitmapKeyFrame); } }
public virtual void DrawExtra(CustomSpriteBatch g, Texture2D sprPixel) { int Index = SpawnFrame; while (Index >= 0) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = DicAnimationKeyFrame[Index]; Vector2 ActivePosition = ActiveKeyFrame.Position; if (ActiveKeyFrame.NextKeyFrame >= 0 && DicAnimationKeyFrame.ContainsKey(ActiveKeyFrame.NextKeyFrame)) { VisibleAnimationObjectKeyFrame NextKeyFrame = DicAnimationKeyFrame[ActiveKeyFrame.NextKeyFrame]; if (ActiveKeyFrame.ListSpecialEffectNode.Count > 0) { Vector2 NextPos = Vector2.Zero; for (int N = 0; N < ActiveKeyFrame.ListSpecialEffectNode.Count; N++) { NextPos = ActiveKeyFrame.ListSpecialEffectNode[N]; g.Draw(sprPixel, new Rectangle((int)ActiveKeyFrame.ListSpecialEffectNode[N].X, (int)ActiveKeyFrame.ListSpecialEffectNode[N].Y, 1, 1), Color.White); g.Draw(sprPixel, new Rectangle((int)ActiveKeyFrame.ListSpecialEffectNode[N].X - 2, (int)ActiveKeyFrame.ListSpecialEffectNode[N].Y - 2, 5, 5), Color.LightGreen); g.DrawLine(sprPixel, new Vector2(ActivePosition.X, ActivePosition.Y), new Vector2(NextPos.X, NextPos.Y), Color.LightGreen); ActivePosition = NextPos; } g.DrawLine(sprPixel, new Vector2(NextPos.X, NextPos.Y), new Vector2(NextKeyFrame.Position.X, NextKeyFrame.Position.Y), Color.LightGreen); } } Index = DicAnimationKeyFrame[Index].NextKeyFrame; } }
protected void UpdateFrom(VisibleAnimationObjectKeyFrame Other) { NextKeyFrame = Other.NextKeyFrame; _IsProgressive = Other._IsProgressive; _Position = Other._Position; MoveValue = Other.MoveValue; _ScaleFactor = Other._ScaleFactor; ScaleValue = Other.ScaleValue; AngleInRad = Other.AngleInRad; AngleValue = Other.AngleValue; _Alpha = Other._Alpha; AlphaValue = Other.AlphaValue; _DrawingDepth = Other._DrawingDepth; DrawingDepthValue = Other.DrawingDepthValue; ListSpecialEffectNode = new List <Vector2>(Other.ListSpecialEffectNode.Count); foreach (Vector2 ActiveNode in Other.ListSpecialEffectNode) { ListSpecialEffectNode.Add(ActiveNode); } }
protected void OnProgressiveNextKeyFrameAnimationSprite(VisibleAnimationObjectKeyFrame ActiveKeyFrame, int KeyFrame, int NextKeyFrame) { NextEvent = ActiveKeyFrame; PositionOld = Position; ScaleFactorOld = ScaleFactor; AngleOld = Angle; AlphaOld = Alpha; DrawingDepthOld = DrawingDepth; EventKeyFrameOld = KeyFrame; NextEventKeyFrame = NextKeyFrame; float KeyFrameChange = KeyFrame - NextKeyFrame; //Calculate of how many pixel the AnimatedBitmap will move per step. ActiveKeyFrame.MoveValue = new Vector2((Position.X - ActiveKeyFrame.Position.X) / KeyFrameChange, (Position.Y - ActiveKeyFrame.Position.Y) / KeyFrameChange); ActiveKeyFrame.ScaleValue = (ScaleFactor - ActiveKeyFrame.ScaleFactor) / KeyFrameChange; ActiveKeyFrame.AngleValue = (Angle - ActiveKeyFrame.AngleInRad) / KeyFrameChange; ActiveKeyFrame.AlphaValue = (Alpha - ActiveKeyFrame.Alpha) / KeyFrameChange; ActiveKeyFrame.DrawingDepthValue = (DrawingDepth - ActiveKeyFrame.DrawingDepth) / KeyFrameChange; }
public override void MoveTimeline(int Difference) { if (NextEventKeyFrame >= 0)//If there is a next key frame, update it. { NextEventKeyFrame += Difference; } foreach (int KeyFrame in Keys) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = DicAnimationKeyFrame[KeyFrame]; if (ActiveKeyFrame.NextKeyFrame >= 0)//If there is a next key frame, update it. { ActiveKeyFrame.NextKeyFrame += Difference; } Add(KeyFrame + Difference, ActiveKeyFrame); Remove(KeyFrame); } //Replace the old Tag. SpawnFrame += Difference; DeathFrame += Difference;//Changing the deathframe will automatically destroy keyframes so only change it after the movement. }
public void DrawNextPositions(CustomSpriteBatch g, Texture2D sprPixel, Color DrawColor) { int Index = SpawnFrame; while (Index >= 0) { VisibleAnimationObjectKeyFrame ActiveKeyFrame = DicAnimationKeyFrame[Index]; g.Draw(sprPixel, new Rectangle((int)ActiveKeyFrame.Position.X - 2, (int)ActiveKeyFrame.Position.Y - 2, 5, 5), null, DrawColor, 0, Vector2.Zero, SpriteEffects.None, 0.1f); Vector2 ActivePosition = ActiveKeyFrame.Position; if (ActiveKeyFrame.NextKeyFrame >= 0 && DicAnimationKeyFrame.ContainsKey(ActiveKeyFrame.NextKeyFrame)) { VisibleAnimationObjectKeyFrame NextKeyFrame = DicAnimationKeyFrame[ActiveKeyFrame.NextKeyFrame]; g.DrawLine(sprPixel, new Vector2(ActivePosition.X, ActivePosition.Y), new Vector2(NextKeyFrame.Position.X, NextKeyFrame.Position.Y), Color.Black); } Index = DicAnimationKeyFrame[Index].NextKeyFrame; } }
public MarkerTimeline(BinaryReader BR, ContentManager Content) : base(BR, TimelineType) { BitmapName = BR.ReadString(); _MarkerType = BR.ReadString(); if (!string.IsNullOrEmpty(BitmapName) && Content != null) { Sprite = Content.Load <Texture2D>("Animations/Sprites/" + BitmapName); } Origin = new Point(Width / 2, Height / 2); int DicAnimationSpriteKeyFrameCount = BR.ReadInt32(); for (int E = 0; E < DicAnimationSpriteKeyFrameCount; E++) { int Key = BR.ReadInt32(); VisibleAnimationObjectKeyFrame NewAnimatedBitmapKeyFrame = new VisibleAnimationObjectKeyFrame(BR); DicAnimationKeyFrame.Add(Key, NewAnimatedBitmapKeyFrame); } }
//Generic Update methods. protected void UpdateAnimationSprite(int KeyFrame) { float ProgressionValue = (KeyFrame - EventKeyFrameOld) / (float)(NextEventKeyFrame - EventKeyFrameOld); if (DicAnimationKeyFrame.ContainsKey(EventKeyFrameOld) && DicAnimationKeyFrame[EventKeyFrameOld].ListSpecialEffectNode.Count > 0) { #region Bezier Curve float t = ProgressionValue; float x0 = PositionOld.X; float x2 = DicAnimationKeyFrame[NextEventKeyFrame].Position.X; float y0 = PositionOld.Y; float y2 = DicAnimationKeyFrame[NextEventKeyFrame].Position.Y; int n = DicAnimationKeyFrame[EventKeyFrameOld].ListSpecialEffectNode.Count + 1; double ResultX = Math.Pow(1 - t, n) * x0; double ResultY = Math.Pow(1 - t, n) * y0; int nFac = 1; for (int k = 1; k <= n; k++) { nFac *= k; } for (int N = 0; N < DicAnimationKeyFrame[EventKeyFrameOld].ListSpecialEffectNode.Count; N++) { int i = N + 1; int niFac = 1; int iFac = 1; for (int k = 1; k <= n - i; k++) { niFac *= k; } for (int k = 1; k <= i; k++) { iFac *= k; } int nChoosek = nFac / (niFac * iFac); //n! / ((n-i)!*i!) * ((1 - t)^(n-1)) * (t ^ i) * Point[i] ResultX += nChoosek * Math.Pow(1 - t, n - i) * Math.Pow(t, i) * DicAnimationKeyFrame[EventKeyFrameOld].ListSpecialEffectNode[N].X; ResultY += nChoosek * Math.Pow(1 - t, n - i) * Math.Pow(t, i) * DicAnimationKeyFrame[EventKeyFrameOld].ListSpecialEffectNode[N].Y; } ResultX += Math.Pow(t, n) * x2; ResultY += Math.Pow(t, n) * y2; Position = new Vector2((float)ResultX, (float)ResultY); #endregion } else { Vector2 Result = NextEvent.MoveValue * (KeyFrame - EventKeyFrameOld); Position = new Vector2(PositionOld.X + (int)Result.X, PositionOld.Y + (int)Result.Y); } ScaleFactor = ScaleFactorOld + NextEvent.ScaleValue * (KeyFrame - EventKeyFrameOld); Angle = AngleOld + NextEvent.AngleValue * (KeyFrame - EventKeyFrameOld); Alpha = AlphaOld + (int)(NextEvent.AlphaValue * (KeyFrame - EventKeyFrameOld)); if (KeyFrame >= NextEventKeyFrame) { NextEvent = null; } }