private void AnimateWalk() { var bodyAnimation = LinkSpriteAtlasFactory.GetAtlasNameFromDirection("BodyWalk", Direction); var spriteEffects = Direction == Direction.Left ? SpriteEffects.FlipHorizontally : SpriteEffects.None; _bodyAnimator.SpriteEffects = spriteEffects; if (_bodyAnimator.IsAnimationActive(bodyAnimation)) { _bodyAnimator.UnPause(); } else { _bodyAnimator.Play(bodyAnimation); } }
public override void Play(string animation, SpriteAnimator.LoopMode loopMode = SpriteAnimator.LoopMode.Loop) { if (SpriteAnimator.IsAnimationActive(animation)) { return; } SpriteAnimator.Play(animation, loopMode); }
void IUpdatable.Update() { var moveDir = new Vector2(_xAxisInput, 0); animation = "playerIdle"; if (moveDir.X != 0 && _collisionState.Below) // moving to the left and right { animation = "playerRun"; StateMachine.ChangeState <Running>(); } else { animation = "playerIdle"; StateMachine.ChangeState <Idle>(); } if (_collisionState.Below && _jumpInput.IsPressed) { _velocity.Y = -Mathf.Sqrt(2f * jumpHeight * gravity); animation = "playerJump"; StateMachine.ChangeState <Jumping>(); } if (_velocity.Y > 0) { animation = "playerFall"; StateMachine.ChangeState <Falling>(); } if (_velocity.Y < 0) { StateMachine.ChangeState <Jumping>(); } _velocity.Y += gravity * Time.DeltaTime; if (!_animator.IsAnimationActive(animation)) { _animator.Play(animation); } //_velocity.X += allomanticForce; _mover.Move(_velocity * Time.DeltaTime, _boxCollider, _collisionState); StateMachine.Update(Time.DeltaTime); if (Input.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.X)) { _velocity.Y = 0; thisScene.Camera.ZoomIn(0.1f); } }
public override void Play(string animation, SpriteAnimator.LoopMode loopMode = SpriteAnimator.LoopMode.Loop) { if (SpriteAnimator.IsAnimationActive(animation)) { return; } if (SpriteAnimator.IsAnimationActive(AttackForwardAnimation) || SpriteAnimator.IsAnimationActive(AttackBackwardAnimation) || SpriteAnimator.IsAnimationActive(AttackSideAnimation)) { if (SpriteAnimator.IsRunning) { return; } } base.Play(animation, loopMode); }
void IUpdatable.Update() { // handle movement and animations var moveDir = new Vector2(_xAxisInput.Value, _yAxisInput.Value); var animation = "WalkDown"; if (moveDir.X < 0) { animation = "WalkLeft"; } else if (moveDir.X > 0) { animation = "WalkRight"; } if (moveDir.Y < 0) { animation = "WalkUp"; } else if (moveDir.Y > 0) { animation = "WalkDown"; } if (moveDir != Vector2.Zero) { if (!_animator.IsAnimationActive(animation)) { _animator.Play(animation); } else { _animator.UnPause(); } var movement = moveDir * _moveSpeed * Time.DeltaTime; _mover.CalculateMovement(ref movement, out var res); _subpixelV2.Update(ref movement); _mover.ApplyMovement(movement); } else { _animator.Pause(); } // handle firing a projectile if (_fireInput.IsPressed) { // fire a projectile in the direction we are facing var dir = Vector2.Zero; switch (_animator.CurrentAnimationName) { case "WalkUp": dir.Y = -1; break; case "WalkDown": dir.Y = 1; break; case "WalkRight": dir.X = 1; break; case "WalkLeft": dir.X = -1; break; default: dir = new Vector2(1, 0); break; } var ninjaScene = Entity.Scene as NinjaAdventureScene; ninjaScene.CreateProjectiles(Entity.Transform.Position, _projectileVelocity * dir); } }
void IUpdatable.Update() { if (Entity.GetComponent <CircleCollider>() != null) { var collider = Entity.GetComponent <CircleCollider>(); //if (collider.CollidesWithAny() } // handle movement and animations var moveDir = new Vector2(_xAxisInput.Value, _yAxisInput.Value); var animation = "Idle"; if (moveDir.X < 0) { if (_crouchInput) { if (!_animator.CurrentAnimationName.Equals("Transition") && !_animator.CurrentAnimationName.Equals("Crouch")) { animation = "Transition"; } else { animation = "Crouch"; } } else { animation = "Walk"; } _animator.FlipX = true; } else if (moveDir.X > 0) { if (_crouchInput) { if (!_animator.CurrentAnimationName.Equals("Transition") && !_animator.CurrentAnimationName.Equals("Crouch")) { animation = "Transition"; } else { animation = "Crouch"; } } else { animation = "Walk"; } _animator.FlipX = false; } if (_kickInput) { moveDir = Vector2.Zero; animation = "Kick"; if (!_animator.IsAnimationActive(animation)) { _animator.Play(animation); } else { _animator.UnPause(); } } else if (moveDir != Vector2.Zero) { if (!_animator.IsAnimationActive(animation)) { _animator.Play(animation); } else { _animator.UnPause(); } if (_crouchInput) { moveDir *= 3; } var movement = moveDir * _moveSpeed * Time.DeltaTime; _mover.CalculateMovement(ref movement, out var res); _subpixelV2.Update(ref movement); _mover.ApplyMovement(movement); } else { if (!_animator.IsAnimationActive(animation)) { _animator.Play(animation); } else { _animator.UnPause(); } } }