/// <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; }
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); }
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; } } }
/// <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; } }
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); }
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; }
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; } } }
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); }
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); } } }
//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); } }
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); } }
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); //} }
//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); } }
internal void Update(GameTime gameTime) { if (CurrentAnimation != null) { CurrentAnimation.Update(gameTime); } }
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); }
private void _btnOriginBottomMiddle_MouseRelease(object sender, MouseButtonActionInfo info) { if (CurrentAnimation == null) { return; } CurrentAnimation.SetOriginAllFrames(Origin.MiddleBottom); }
private void _btnOriginTopLeft_MouseRelease(object sender, MouseButtonActionInfo info) { if (CurrentAnimation == null) { return; } CurrentAnimation.SetOriginAllFrames(Origin.TopLeft); }
public override void Execute() { base.Execute(); if (CurrentAnimation.Frames.Length > 1) { CurrentAnimation.RemoveFrame(CurrentAnimation.CurrentFrameIndex); } }
public void Play(string name) { if (_animations.ContainsKey(name)) { CurrentAnimation = _animations[name]; CurrentAnimation.ResetAnimation(); } }
internal void SetAnimation(SPRITE_ANIMATION newAnimationState) { if (newAnimationState != CurrentAnimationState) { CurrentAnimationState = newAnimationState; CurrentAnimation.Reset(); } }
public override void Reset() { if (!IsGhost) { CurrentAnimation = ConstructionAnimation; CurrentAnimation.Reset(); } }
public override void Draw(GameTime gameTime, SpriteBatch batch) { base.Draw(gameTime, batch); if (CurrentAnimation != null) { CurrentAnimation.Draw(batch); } }
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); } }
/// <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); }
new public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) { if (CurrentAnimation != null) { CurrentAnimation.Update(gameTime); } base.Update(gameTime, chunks, camera); }
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())); }
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); } }
public override void Update(GameTime gameTime) { if (sprite == null) { return; } CurrentAnimation.Update(gameTime); base.Update(gameTime); }