/// <summary> /// Event Listener for the Play Button on the main screen /// Toggles the video between play and pause /// </summary> private void PlayButton_Click(object sender, RoutedEventArgs e) { if (isPlaying) //If the current flag is set to true { ClipPlayer.Pause(); //pause the video isPlaying = false; PlayButton.Visibility = Visibility.Hidden; //Hide the play button graphic PauseButton.Visibility = Visibility.Visible; //show the pause button graphic } else { ClipPlayer.Play(); //play the video isPlaying = true; ClipPlayer.Position = TimeSpan.FromSeconds(0); //Reset the clip PlayButton.Visibility = Visibility.Visible; //Show the play button graphic PauseButton.Visibility = Visibility.Hidden; //hide the pause button graphic } }
private void OnSceneEvent(Enums.SceneState state) { if (ClipPlayer.CurrentSequence != null) { switch (state) { case Enums.SceneState.Playing: ClipPlayer.Play(ClipPlayer.CurrentSequence.Name, ClipPlayer.IsLooped); break; case Enums.SceneState.Stopped: { CurrentPathLerpPosition = StartPathingLerpPosition; CurrentPathNodeIndex = StartPathNodeIndex; ClipPlayer.Stop(true); } break; } } }
/// <summary> /// Event Listener that fires when the file drop down changes /// </summary> private void ClipDropDown_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ClipDropDown.SelectedIndex != -1) //as long as your not on a null selection { string text = ClipDropDown.SelectedItem.ToString(); //store the selected item out to a string foreach (FileElement info in fileList) //check through all the files { if (info.Title.Equals(text)) //If you find one that matches { ClipDes.Text = info.Description; //set the main page description to the selected items description ClipPlayer.Source = new Uri(ClipFolder + "/" + info.FileName, UriKind.RelativeOrAbsolute); //set the source of the media player to the selected item ClipPlayer.Play(); //play the video clip ClipPlayer.ScrubbingEnabled = true; //allow scrubbing ClipPlayer.Position = TimeSpan.FromSeconds(2); //move the video forward two seconds. This allows for a really basic thumbnail ClipPlayer.Pause(); //pause the video } } } }
public void Play(string sequence, bool loop) { ClipPlayer.Play(sequence, loop); }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (!Enabled) return; float elapsed = (float) gameTime.ElapsedGameTime.TotalSeconds*0.33f; switch (Direction) { case Direction.Left: ClipPlayer.IsFlipped = true; break; case Direction.Right: ClipPlayer.IsFlipped = false; break; } if (ClipPlayer.Texture != null && ClipPlayer.CurrentSequence != null && ClipPlayer.CurrentSequence.Frames.Count > 0) { #region Pathing Nodes if (AttachedPathingNode != null) { // We are attached to a path check for nodes in the path if (AttachedPathingNode.Nodes.Count > 0) { SpriteEffects = AttachedPathingNode.Nodes[CurrentPathNodeIndex].SpriteEffect; // Update our draw order to be the same as the current node we are on if (AttachedPathingNode.UseNodesDrawOrder) DrawOrder = AttachedPathingNode.Nodes[CurrentPathNodeIndex].DrawOrder; // See if we should alter our animation sequence if (AttachedPathingNode.Nodes[CurrentPathNodeIndex].AnimationSequence != null && CurrentPathLerpPosition == 0) { // Update our Clip Player ClipPlayer.Play(AttachedPathingNode.Nodes[CurrentPathNodeIndex].AnimationSequence.Name, AttachedPathingNode.Nodes[CurrentPathNodeIndex].IsLooped); } if (CurrentPathNodeIndex <= (AttachedPathingNode.Nodes.Count - 1)) { if (AttachedPathingNode.IsTraveling) { // Lerp to our next node CurrentPathLerpPosition += (AttachedPathingNode.Nodes[CurrentPathNodeIndex].TravelSpeed*elapsed); } if (CurrentPathLerpPosition >= 1) { if (IsLerpingBackToFirstNode) { CurrentPathNodeIndex--; CurrentPathLerpPosition = 0; } else { if (CurrentPathNodeIndex < (AttachedPathingNode.Nodes.Count - 1)) { CurrentPathNodeIndex++; CurrentPathLerpPosition = 0; } } } // Check to see we are on the last node in the chain if (CurrentPathNodeIndex == (AttachedPathingNode.Nodes.Count - 1) && !IsLerpingBackToFirstNode) { // we want to respawn back to the first so reset everything switch (AttachedPathingNode.LedgeTavelAlgo) { case LedgeTravelAlgo.RespawnAtFirstNode: if (AttachedPathingNode.Nodes[CurrentPathNodeIndex].RespawnDelay > TimeSpan.Zero) { if (AttachedPathingNode.Nodes[CurrentPathNodeIndex].NodeElapsedTime > AttachedPathingNode.Nodes[CurrentPathNodeIndex].RespawnDelay) { // purge the last node elapsed time AttachedPathingNode.Nodes[CurrentPathNodeIndex].NodeElapsedTime = TimeSpan.Zero; // Reset to the begining pathing node CurrentPathNodeIndex = 0; // Reset our Lerp CurrentPathLerpPosition = 0; } else { AttachedPathingNode.Nodes[CurrentPathNodeIndex].NodeElapsedTime += gameTime.ElapsedGameTime; } } else { // Reset to the begining pathing node CurrentPathNodeIndex = 0; // Reset our Lerp CurrentPathLerpPosition = 0; } break; case LedgeTravelAlgo.LerpToFirstNode: IsLerpingBackToFirstNode = true; CurrentPathLerpPosition = 0; break; case LedgeTravelAlgo.StopAtLastNode: AttachedPathingNode.IsTraveling = false; CurrentPathLerpPosition = 0; break; } } else if (CurrentPathNodeIndex == 0 && IsLerpingBackToFirstNode) { IsLerpingBackToFirstNode = false; CurrentPathLerpPosition = 0; } else { // Continue to move along the path if (IsLerpingBackToFirstNode) { // Lerping Rotation Calculation ** value1 + (value2 - value1) * amount ** float n1 = AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Rotation; float n2 = AttachedPathingNode.Nodes[CurrentPathNodeIndex].Rotation; Rotation = n1 + (n2 - n1) * CurrentPathLerpPosition; // Moving Back towards the last node Position = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Position, AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Position, CurrentPathLerpPosition); // Scaling Scale = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Scale, AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Scale, CurrentPathLerpPosition); } else { // Lerping Rotation Calculation ** value1 + (value2 - value1) * amount ** float n1 = AttachedPathingNode.Nodes[CurrentPathNodeIndex].Rotation; float n2 = AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Rotation; Rotation = n1 + (n2 - n1) * CurrentPathLerpPosition; // Moving Position = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Position, AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Position, CurrentPathLerpPosition); // Scaling Scale = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Scale, AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Scale, CurrentPathLerpPosition); } } } } } #endregion // Incase it walks past the max frame count on the sequences if (ClipPlayer.CurrentFrameIndex >= ClipPlayer.CurrentSequence.Frames.Count) { if (ClipPlayer.IsLooped) ClipPlayer.CurrentFrameIndex = 0; else ClipPlayer.CurrentFrameIndex = ClipPlayer.CurrentSequence.Frames.Count - 1; } float tw = (ClipPlayer.CurrentSequence.Frames[ClipPlayer.CurrentFrameIndex].SourceRectangle.Width + BoundingBoxScale.X)*Scale.X; float th = (ClipPlayer.CurrentSequence.Frames[ClipPlayer.CurrentFrameIndex].SourceRectangle.Height + BoundingBoxScale.Y)*Scale.Y; if (IsCentered) { // Center Aligned means the position is actually in the center of the actor and needs to remove that float widthHalf = tw/2; float heightHalf = th/2; float posX1 = Position.X - widthHalf; float posY1 = Position.Y - heightHalf; float posX2 = Position.X + widthHalf; float posY2 = Position.Y + heightHalf; // Update our Bounding Box Vector3[] points = new Vector3[2]; points[0] = new Vector3(posX1 + CameraOffsetX, posY1 + CameraOffsetY, -5); points[1] = new Vector3(posX2 + CameraOffsetX, posY2 + CameraOffsetY, 5); BoundingBox = BoundingBox.CreateFromPoints(points); } else { // Update our Bounding Box Vector3[] points = new Vector3[2]; points[0] = new Vector3(Position.X + CameraOffsetX, Position.Y + CameraOffsetY, -5); points[1] = new Vector3(Position.X + CameraOffsetX + tw, Position.Y + CameraOffsetY + th, 5); // Create our Bounding Box BoundingBox = BoundingBox.CreateFromPoints(points); } if (BoundingBoxRenderer != null) { BoundingBoxRenderer.ShowBoundingBox = ShowBoundingBox; BoundingBoxRenderer.BoundingBox = BoundingBox; BoundingBoxRenderer.Update(gameTime); } // Update our Clip Player ClipPlayer.IsCentered = IsCentered; ClipPlayer.Position = Position; ClipPlayer.Velocity = Velocity; ClipPlayer.Scale = Scale; ClipPlayer.Rotation = Rotation; ClipPlayer.SpriteEffects = SpriteEffects; ClipPlayer.CameraOffsetX = CameraOffsetX; ClipPlayer.CameraOffsetY = CameraOffsetY; ClipPlayer.CameraZoomOffset = CameraZoomOffset; ClipPlayer.BoundingBox = BoundingBox; ClipPlayer.ShowBoundingBox = ShowBoundingBox; ClipPlayer.Update(gameTime); } }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (Globals.IsScenePaused) { return; } CameraOffsetX = Globals.CurrentCameraOffsetX; CameraOffsetY = Globals.CurrentCameraOffsetY; CameraZoomOffset = Globals.CurrentCameraZoom; float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds * 0.15f; if (ClipPlayer.CurrentSequence != null) { if (BoundingBoxRenderer != null) { if (RenderWindow.FollowingObject == this) { BoundingBoxRenderer.Color = Color.Green; } else { BoundingBoxRenderer.Color = Color.Yellow; } } if (AttachedPathingNode != null) { // We are attached to a path check for nodes in the path if (AttachedPathingNode.Nodes.Count > 0) { ClipPlayer.SpriteEffects = AttachedPathingNode.Nodes[CurrentPathNodeIndex].SpriteEffect; // Update our draw order to be the same as the current node we are on DrawOrder = AttachedPathingNode.Nodes[CurrentPathNodeIndex].DrawOrder; // See if we should alter our animation sequence if (AttachedPathingNode.Nodes[CurrentPathNodeIndex].AnimationSequence != null && !Globals.IsScenePaused && !Globals.IsSceneStopped) { // Update our Clip Player ClipPlayer.Play(AttachedPathingNode.Nodes[CurrentPathNodeIndex].AnimationSequence.Name, AttachedPathingNode.Nodes[CurrentPathNodeIndex].IsLooped); } if (CurrentPathNodeIndex <= (AttachedPathingNode.Nodes.Count - 1)) { if (AttachedPathingNode.IsTraveling && !Globals.IsScenePaused) { // Lerp to our next node CurrentPathLerpPosition += (AttachedPathingNode.Nodes[CurrentPathNodeIndex].TravelSpeed * elapsed); } if (CurrentPathLerpPosition >= 1) { if (IsLerpingBackToFirstNode) { CurrentPathNodeIndex--; CurrentPathLerpPosition = 0; } else { if (CurrentPathNodeIndex < (AttachedPathingNode.Nodes.Count - 1)) { CurrentPathNodeIndex++; CurrentPathLerpPosition = 0; } } } // Check to see we are on the last node in the chain if (CurrentPathNodeIndex == (AttachedPathingNode.Nodes.Count - 1) && !IsLerpingBackToFirstNode) { // we want to respawn back to the first so reset everything if (AttachedPathingNode.LedgeTavelAlgo == LedgeTravelAlgo.RespawnAtFirstNode) { // Reset to the begining pathing node CurrentPathNodeIndex = 0; // Reset our Lerp CurrentPathLerpPosition = 0; } else if (AttachedPathingNode.LedgeTavelAlgo == LedgeTravelAlgo.LerpToFirstNode) { // Flag we are lerping back to the last node IsLerpingBackToFirstNode = true; CurrentPathLerpPosition = 0; } else if (AttachedPathingNode.LedgeTavelAlgo == LedgeTravelAlgo.StopAtLastNode) { AttachedPathingNode.IsTraveling = false; CurrentPathLerpPosition = 0; } } else if (CurrentPathNodeIndex == 0 && IsLerpingBackToFirstNode) { IsLerpingBackToFirstNode = false; CurrentPathLerpPosition = 0; } else { // Continue to move along the path if (IsLerpingBackToFirstNode) { // Lerping Rotation Calculation ** value1 + (value2 - value1) * amount ** float n1 = AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Rotation; float n2 = AttachedPathingNode.Nodes[CurrentPathNodeIndex].Rotation; Rotation = n1 + (n2 - n1) * CurrentPathLerpPosition; // Moving Back towards the last node Position = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Position, AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Position, CurrentPathLerpPosition); // Scaling Scale = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Scale, AttachedPathingNode.Nodes[CurrentPathNodeIndex - 1].Scale, CurrentPathLerpPosition); } else { // Lerping Rotation Calculation ** value1 + (value2 - value1) * amount ** float n1 = AttachedPathingNode.Nodes[CurrentPathNodeIndex].Rotation; float n2 = AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Rotation; Rotation = n1 + (n2 - n1) * CurrentPathLerpPosition; // Moving Position = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Position, AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Position, CurrentPathLerpPosition); // Scaling Scale = Vector2.Lerp(AttachedPathingNode.Nodes[CurrentPathNodeIndex].Scale, AttachedPathingNode.Nodes[CurrentPathNodeIndex + 1].Scale, CurrentPathLerpPosition); } } } } } if (IsSelected) { if (AttachedPathingNode != null) { AttachedPathingNode.IsSelected = true; foreach (var n in AttachedPathingNode.Nodes) { n.IsSelected = true; } } ShowBoundingBox = true; } else { if (AttachedPathingNode != null) { AttachedPathingNode.IsSelected = false; foreach (var n in AttachedPathingNode.Nodes) { n.IsSelected = false; } } ShowBoundingBox = false; } } }