/// <summary> /// When Play button is pressed, this event executes /// </summary> private void Play_Click(object sender, RoutedEventArgs e) { if (InputHandling.isNumeric(imageXIndexTextBox, imageYIndexTextBox, SpritesPerColumnTextBox, SpritesPerRowTextBox)) { if ((SpritesPerRowTextBox.Text != "") && (SpritesPerColumnTextBox.Text != "") && (imageYIndexTextBox.Text != "") && (imageXIndexTextBox.Text != "") && (frameCount.Text != "") && (ImageFileNameTextBox.Text != "") && _IsPlaying == false) { _IsPlaying = true; _CurrentPlaying = true; _BackgroundWorker.RunWorkerAsync(); int frameSpeed = (int)(Convert.ToSingle(txtAnimationDuration.Text) * 1000); if (frameSpeed < minSpeed) { txtAnimationDuration.Text = "0.05"; } duration = string.IsNullOrEmpty(txtAnimationDuration.Text) ? 125 : Math.Max(frameSpeed, minSpeed); } else if (_IsPlaying && _CurrentPlaying) { //nothing should happen because its playing so no errors } else { MessageBoxes.Alert_PopUP("Missing field entries"); } } }
/// <summary> /// Get the Rectangle of the next frame to play, and draw it in the port. /// </summary> /// <param name="currentAnimIndex"></param> /// <param name="imageYIndexTextBox"></param> /// <param name="imageXIndexTextBox"></param> /// <param name="numberOfFrames"></param> /// <param name="SpritesPerRowTextBox"></param> /// <param name="FileNameTextBox"></param> /// <param name="SpritesPerColumnTextBox"></param> /// <param name="Test_Img"></param> /// <returns></returns> public static int PlayNextFrame(int currentAnimIndex, TextBox imageYIndexTextBox, TextBox imageXIndexTextBox, TextBox numberOfFrames, TextBox SpritesPerRowTextBox, TextBox FileNameTextBox, TextBox SpritesPerColumnTextBox, System.Windows.Controls.Image Test_Img) { currentAnimIndex++; try { System.Drawing.Image imgsrc = System.Drawing.Image.FromFile(FileNameTextBox.Text); int Yindex = Convert.ToInt16(imageYIndexTextBox.Text); int Xindex = Convert.ToInt16(imageXIndexTextBox.Text); int spriteHeight = imgsrc.Height / (Convert.ToInt16(SpritesPerColumnTextBox.Text)); int spriteWidth = imgsrc.Width / (Convert.ToInt16(SpritesPerRowTextBox.Text)); int totalFrames = Convert.ToInt16(numberOfFrames.Text); if (currentAnimIndex >= totalFrames) { currentAnimIndex = 0; } int animationWidth = (Xindex + currentAnimIndex) * spriteWidth; int X = animationWidth % imgsrc.Width; int Y = (Yindex + (animationWidth / imgsrc.Width)) * spriteHeight; Test_Img.Source = SpritePreviewer.ImgViewAtN(imgsrc, X, Y, spriteWidth, spriteHeight); if (Test_Img.Source == null) { //calling a method to throw a pop up to alert user that //their sprite specification is not right MessageBoxes.Alert_PopUP("Image Specification Incorrect." + "\n" + "Please check image requirements." + "\n" + "(Sprite per row * Sprite width) = Image Height" + "\n" + "(Sprite per column * Sprite width) = Image Width"); } } catch { } return(currentAnimIndex); }