Пример #1
0
        /// <summary>
        /// This is a thread worker. It performs the continuous animation until Stop is called.
        /// </summary>
        private void AnimateContinuosly()
        {
            IsPendingStop = false;

            var startFrameTime = DateTime.UtcNow;

            using (var tickLock = new ManualResetEvent(false))
            {
                while (IsPendingStop == false)
                {
                    startFrameTime = DateTime.UtcNow;
                    FrameNumber    = (FrameNumber == UInt64.MaxValue) ? 1 : FrameNumber + 1;

                    lock (SyncLock)
                    {
                        CurrentAnimation.PaintNextFrame();
                        LedStrip.Render();
                    }

                    var elapsedToFrame = MillisecondsPerFrame - Convert.ToInt32(DateTime.UtcNow.Subtract(startFrameTime).TotalMilliseconds);

                    if (elapsedToFrame <= 0)
                    {
                        $"Frames are lagging. Increase the frequency or simplify the rendering logic.".Warn(); // typeof(LedStripWorker));
                        continue;
                    }
                    else
                    {
                        tickLock.WaitOne(elapsedToFrame);
                    }
                }
            }

            IsPendingStop = false;
        }
Пример #2
0
        public bool Play(string AniName, string BackToAnim = "")
        {
            int index = -1;

            if (IsLoaded)
            {
                if (CurrentAnimation.ToLower() != AniName.ToLower())
                {
                    try
                    {
                        index = Animations.IndexOf(Animations.Single(a => a.Name.ToLower() == AniName.ToLower()));
                    }
                    catch
                    {
                        index = -1;
                    }

                    BackAnimation = null;
                    if (!string.IsNullOrEmpty(BackToAnim))
                    {
                        BackToAnimation(BackToAnim);
                    }
                    return(onPlayName(index, AniName));
                }
            }
            return(false);
        }
Пример #3
0
        public void SetCurrentAnimation(string name)
        {
            if (!_animations.ContainsKey(name))
            {
                throw new ArgumentException("cannot find the animation: " + name);
            }

            if (name != _currentAnimation)
            {
                if (!CurrentAnimation.FinishBeforeTransition)
                {
                    // Switch immediately to the new animation
                    _currentAnimation = name;
                    CurrentAnimation.Reset();
                }
                else
                {
                    // Set the current animation to wait for the end, upon finishing, switch animations
                    CurrentAnimation.WaitForEnd();
                    EventHandler <AnimationEventArgs> animSwitch = (sender, args) =>
                    {
                        _currentAnimation = name;
                        CurrentAnimation.Reset();
                    };
                    CurrentAnimation.AnimationFinished += animSwitch;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Moves the currently active Animation one ticks further in its sequence.
        /// </summary>
        public void Update()
        {
            if (CurrentAnimation == null || CurrentElement == null)
            {
                return;
            }

            m_finishedanimation = false;
            ++m_animationtime;

            if (m_elementswitchtime == -1)
            {
                return;
            }

            if (m_elementswitchtime > 1)
            {
                --m_elementswitchtime;
            }
            else
            {
                var newlement = CurrentAnimation.GetNextElement(CurrentElement.Id);

                if (newlement.Id <= CurrentElement.Id)
                {
                    m_animationinloop   = true;
                    m_finishedanimation = true;
                }

                m_currentelement    = newlement;
                m_elementswitchtime = CurrentElement.Gameticks;
            }
        }
Пример #5
0
        public override void Update(GameTime gameTime, GameInfo gameInfo)
        {
            if (Properties != null)
            {
                if (Info.AnimationProperty != Util.GetEngineNull() && CurrentAnimationKey != Properties[Info.AnimationProperty].GetAsString())
                {
                    CurrentAnimationKey = Properties[Info.AnimationProperty].GetAsString();
                    CurrentAnimation    = ContentLoader.GetAnimation(CurrentAnimationKey);

                    if (CurrentAnimation != null)
                    {
                        CurrentAnimation.Play();
                    }
                    else
                    {
                        CurrentAnimation = Info.DefaultAnimation;
                    }
                }
            }

            foreach (ComponentInfo component in Components)
            {
                component.Update(gameTime, gameInfo);
            }

            base.Update(gameTime, gameInfo);
        }
Пример #6
0
 public void UpdatePosition()
 {
     if (this.state == CurrentAnimation.MoveDown)
     {
         move = new Vector3(0, -1, 0);
     }
     else if (this.state == CurrentAnimation.MoveUp)
     {
         move = new Vector3(0, 1, 0);
     }
     else if (this.state == CurrentAnimation.MoveLeft)
     {
         move = new Vector3(-1, 0, 0);
     }
     else if (this.state == CurrentAnimation.MoveRight)
     {
         move = new Vector3(1, 0, 0);
     }
     else if (this.state == CurrentAnimation.TurnLeft)
     {
         rotation = 90;
     }
     else if (this.state == CurrentAnimation.TurnRight)
     {
         rotation = -90;
     }
     this.state = CurrentAnimation.None;
 }
Пример #7
0
        public override void Update(GameTime gameTime)
        {
            CurrentAnimation.NextFrame(gameTime);

            bool collided = CheckColision();

            Body.CollisionCategories = Collide.Instance.HeroGroup;

            if (Active && collided)
            {
                Active = false;
                Alpha  = 0.5f;
                ChangeGravity();
            }
            else if (!Active)
            {
                time += gameTime.ElapsedGameTime.Milliseconds;

                if (time >= 500)
                {
                    time   = 0;
                    Active = true;
                    Alpha  = 1f;
                }
            }
        }
Пример #8
0
 public override void Update(GameTime gameTime)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Update(gameTime);
     }
 }
        public override void Update(GameTime gameTime, GameInfo gameInfo)
        {
            // Update animation
            CurrentAnimation.Update(gameTime);

            base.Update(gameTime, gameInfo);
        }
Пример #10
0
 public void DrawFrame()
 {
     if (CurrentAnimation != null)
     {
         if (Shader != null)
         {
             Game.SpriteBatch.End();
             Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
             Shader.Apply();
         }
         Game.SpriteBatch.Draw(
             CurrentAnimation.SpriteSheet,
             new Vector2(Owner.Body.BoxCollider.X, Owner.Body.BoxCollider.Y) - CurrentAnimation.Offset,
             CurrentAnimation.GetDrawRect(_drawIndex),
             Color.White,
             0,
             Vector2.Zero,
             1f,
             Facing == Orientation.Right ? SpriteEffects.None : SpriteEffects.FlipHorizontally,
             LayerDepth
             );
         if (Shader != null)
         {
             Game.SpriteBatch.End();
             Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
         }
     }
 }
Пример #11
0
 //draw the frame, no stretching.
 public void Draw(AD2SpriteBatch sb, int x, int y, Color tint)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Draw(sb, XFrame, YFrame, x, y, tint);
     }
 }
Пример #12
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (this.IsGhost)
            {
                CurrentAnimation = IdleAnimation;
            }

            CurrentAnimation.Update(gameTime);
            if (CurrentAnimation.HasFinished)
            {
                CurrentAnimation = CurrentAnimation.NextAnimation;
            }



            if (HasMouseFocus)
            {
                UpdateStatusScreen();
            }

            if (!IsGhost)
            {
                GetSimEntity().Update(gameTime);
            }
        }
Пример #13
0
        new public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            CalculateCurrentOrientation(camera);

            //foreach (string orient in OrientationStrings)
            //{
            //    string animationName = currentMode + orient;

            //    if (!Animations.ContainsKey(animationName)) continue;

            //    Animation animation = Animations[animationName];
            //    animation.Update(gameTime);
            //}

            string s = currentMode + OrientationStrings[(int)CurrentOrientation];

            if (Animations.ContainsKey(s))
            {
                var previousAnimation = CurrentAnimation;
                CurrentAnimation = Animations[s];
                if (previousAnimation != null && previousAnimation.Name.StartsWith(currentMode))
                {
                    CurrentAnimation.Sychronize(previousAnimation);
                }
                SpriteSheet = CurrentAnimation.SpriteSheet;
            }

            base.Update(gameTime, chunks, camera);

            //if (CurrentAnimation != null && CurrentAnimation.LastFrame != CurrentAnimation.CurrentFrame)
            //{
            //    InvokeOnFrame(CurrentAnimation, CurrentOrientation, CurrentAnimation.CurrentFrame);
            //}
        }
Пример #14
0
 //draw the frame, but can be stretched
 public void Draw(AD2SpriteBatch sb, int x, int y, int w, int h)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Draw(sb, XFrame, YFrame, x, y, w, h);
     }
 }
Пример #15
0
 internal void Update(GameTime gameTime)
 {
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Update(gameTime);
     }
 }
Пример #16
0
        public override void Render(Canvas2D canvas)
        {
            base.Render(canvas);

            if (CurrentAnimation != null && CurrentAnimation.Frames.Count > 0)
            {
                canvas.DrawText(Font, Vector2.Zero,
                                string.Format("Frame: {0}/{1} | Offset: {2};{3} | Origin:{4};{5}",
                                              CurrentAnimation.CurrentFrameIndex + 1, CurrentAnimation.Frames.Count,
                                              CurrentAnimation.CurrentFrame.OffSetX,
                                              CurrentAnimation.CurrentFrame.OffSetY,
                                              (int)CurrentAnimation.CurrentFrame.OriginX,
                                              (int)CurrentAnimation.CurrentFrame.OriginY), ColorU.White);
                using (canvas <= Camera.Transformation)
                {
                    CurrentAnimation.Draw(canvas);
                    if (_drawFrameDebug && CurrentAnimation.Frames.Count > 0)
                    {
                        Frame curFrame = CurrentAnimation.CurrentFrame;
                        canvas.DrawRect(
                            Rect.FromBox(curFrame.OffSetX - curFrame.SpriteFrame.Width / 2f,
                                         curFrame.OffSetY - curFrame.SpriteFrame.Height / 2, curFrame.SpriteFrame.Width,
                                         curFrame.SpriteFrame.Height), ColorU.Red);
                        canvas.DrawLine(-5, 0, 5, 0, _originMarkLineStyle, ColorU.GreenYellow);
                        canvas.DrawLine(0, -5, 0, 5, _originMarkLineStyle, ColorU.GreenYellow);
                    }
                }
            }

            guiManager.DrawControls(canvas);
        }
Пример #17
0
 private void _btnOriginBottomMiddle_MouseRelease(object sender, MouseButtonActionInfo info)
 {
     if (CurrentAnimation == null)
     {
         return;
     }
     CurrentAnimation.SetOriginAllFrames(Origin.MiddleBottom);
 }
Пример #18
0
 private void _btnOriginTopLeft_MouseRelease(object sender, MouseButtonActionInfo info)
 {
     if (CurrentAnimation == null)
     {
         return;
     }
     CurrentAnimation.SetOriginAllFrames(Origin.TopLeft);
 }
Пример #19
0
 public override void Execute()
 {
     base.Execute();
     if (CurrentAnimation.Frames.Length > 1)
     {
         CurrentAnimation.RemoveFrame(CurrentAnimation.CurrentFrameIndex);
     }
 }
Пример #20
0
 public void Play(string name)
 {
     if (_animations.ContainsKey(name))
     {
         CurrentAnimation = _animations[name];
         CurrentAnimation.ResetAnimation();
     }
 }
Пример #21
0
 internal void SetAnimation(SPRITE_ANIMATION newAnimationState)
 {
     if (newAnimationState != CurrentAnimationState)
     {
         CurrentAnimationState = newAnimationState;
         CurrentAnimation.Reset();
     }
 }
Пример #22
0
 public override void Reset()
 {
     if (!IsGhost)
     {
         CurrentAnimation = ConstructionAnimation;
         CurrentAnimation.Reset();
     }
 }
Пример #23
0
 public override void Draw(GameTime gameTime, SpriteBatch batch)
 {
     base.Draw(gameTime, batch);
     if (CurrentAnimation != null)
     {
         CurrentAnimation.Draw(batch);
     }
 }
Пример #24
0
        public void Draw(SpriteBatch sb)
        {
            var effect = InvulnerabilityTimer > 0 ? AnimationEffect.FlashWhite : AnimationEffect.None;

            if (CurrentAnimation != null)
            {
                CurrentAnimation.Draw(sb, (Direction == FaceDirection.Left ? SpriteEffects.FlipHorizontally : SpriteEffects.None), Transform.Position, 0, 1f, Color.White, effect);
            }
        }
Пример #25
0
 /// <summary>
 /// Starts playing an animation on this skeleton.
 /// </summary>
 /// <param name="name">Name of animation, as assigned in the Pose editor. Case sensitive.</param>
 /// <param name="startTimeSeconds">The starttime of the animation (first frame) in seconds. Often this will be the gametime of the current frame, but you can use this to offset the animation's time position.</param>
 public void StartAnimation(string name, float startTimeSeconds)
 {
     if (!_animations.TryGetValue(name, out var animation))
     {
         throw new PoseAnimationNotFoundException($"Animation \"{name}\" not found.");
     }
     CurrentAnimation = animation;
     CurrentAnimation.Start(startTimeSeconds);
 }
Пример #26
0
        new public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (CurrentAnimation != null)
            {
                CurrentAnimation.Update(gameTime);
            }

            base.Update(gameTime, chunks, camera);
        }
Пример #27
0
        public void SetCurrentFrame(Frame frame)
        {
            if (CurrentAnimation != null)
            {
                CurrentAnimation.Stop();
            }

            CurrentFrame = frame;
        }
        public virtual Dictionary <string, Sprite> GetSpriteBoxes()
        {
            if (CurrentAnimation == null || CurrentAnimation.GetCurrentSprite() == null)
            {
                return(new Dictionary <string, Sprite>());
            }

            return(FromJsonSprites(CurrentAnimation.GetCurrentSprite()));
        }
Пример #29
0
        public void Draw(SpriteBatch sb)
        {
            var flip = (Direction == FaceDirection.Left);

            if (CurrentAnimation != null)
            {
                CurrentAnimation.Draw(sb, (flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None), Transform.Position, Rotation, 0.5f, Color.White, AnimationEffect.None);
            }
        }
Пример #30
0
 public override void Update(GameTime gameTime)
 {
     if (sprite == null)
     {
         return;
     }
     CurrentAnimation.Update(gameTime);
     base.Update(gameTime);
 }