Advertisement
xMissCorielx

Animation Station

Jan 13th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Drawing.Imaging;
  12. using System.Xml.Schema;
  13.  
  14. namespace NPC_Creator
  15. {
  16.     public partial class AnimationStation : Form
  17.     {
  18.         Bitmap image1; //Frames
  19.         string systemName;
  20.         int xframe = 16;
  21.         int yframe = 32;
  22.  
  23.         public AnimationStation()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.         public Rectangle GetTileArea(int tileIndex, int tileSize, int sheetWidth)
  28.         {
  29.             int x = tileIndex % sheetWidth;
  30.             int y = tileIndex / sheetWidth;
  31.             return new Rectangle(x * tileSize, y * tileSize, tileSize, tileSize);
  32.         }
  33.         private void AnimationStation_Load(object sender, EventArgs e)
  34.         {
  35.             systemName = scheduleStudio.importSystem;
  36.             int xmin = (int)frameCount.Value * 16 - 1;
  37.             if (xmin < 0)
  38.             {
  39.                 xmin = 0;
  40.             }
  41.             int ymin = (int)frameCount.Value * 32 - 1;
  42.             if (ymin < 0)
  43.             {
  44.                 ymin = 0;
  45.             }
  46.             if (xmin > 48)
  47.             {
  48.                 xmin = xmin / 4;
  49.             }
  50.             int xmaximum = xmin + 16;
  51.             int ymaximum = ymin + 32;
  52.             try
  53.             {
  54.                 //Get Spritesheet
  55.                 image1 = new Bitmap(Environment.CurrentDirectory + $"\\Export\\[CP]{systemName}\\assets\\img\\spritesheet.png");
  56.                 Rectangle tileArea = this.GetTileArea(tileIndex: 0, tileSize: 16, sheetWidthInTiles: 4);
  57.                 Rectangle rect = new Rectangle(xmin, ymin, xmaximum, ymaximum);
  58.                 Bitmap spriteFrame = image1.Clone(rect, PixelFormat.DontCare);
  59.                 pictureBox1.Image = spriteFrame;
  60.                
  61.             }
  62.             catch (Exception ex)
  63.             {
  64.  
  65.             }
  66.         }
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement