Advertisement
Guest User

Untitled

a guest
Jan 6th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. public virtual void AnimateTransformTo(Vector2 position, float zoom, float speed, bool linear = true) {
  2.    animateLinear = linear;
  3.    animateEndPosition = position;
  4.    animateEndZoom = zoom;
  5.    animateSpeed = speed;
  6.    animateTime = -1f;
  7.    animateTransform = true;
  8. }
  9.      
  10.  
  11. public virtual void Update(GameTime gametime) {
  12.    if (animateTransform) {
  13.       if (animateTime == -1f) {
  14.          animateStartPosition = m_position;
  15.          animateStartZoom = m_zoom;
  16.          animateTime = (float)gametime.TotalGameTime.TotalSeconds;
  17.          OnAnimateTransformStart(this, new AnimateTransformEventArgs(animateTime, 0f, animateEndPosition, animateEndZoom, animateSpeed));
  18.       }
  19.       float time = (float)gametime.TotalGameTime.TotalSeconds;
  20.       float progress = ((time - animateTime) / 100) * animateSpeed;
  21.       if (progress >= 1f) progress = 1f;
  22.       //if (animateLinear) LerpTransformLinear(animateStartPosition, animateEndPosition, animateStartZoom, animateEndZoom, progress);
  23.       //else LerpTransformLinear(m_position, animateEndPosition, m_zoom, animateEndZoom, progress);
  24.       if (animateLinear) LerpTransformLinear(out m_transform, new Vector2(m_viewport.Width, m_viewport.Height), animateStartPosition, animateEndPosition, animateStartZoom, animateEndZoom, progress);
  25.       else LerpTransformLinear(out m_transform, new Vector2(m_viewport.Width, m_viewport.Height), m_position, animateEndPosition, m_zoom, animateEndZoom, progress);
  26.       OnAnimateTransform(this, new AnimateTransformEventArgs(time, progress, animateEndPosition, animateEndZoom, animateSpeed));
  27.       if (progress >= 1f) {
  28.          animateTransform = false;
  29.          OnAnimateTransformEnd(this, new AnimateTransformEventArgs(time, progress, animateEndPosition, animateEndZoom, animateSpeed));
  30.       }
  31.    }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement