예제 #1
0
 public void SetSprite(SpriteData data, int frame)
 {
     pictureBox1.Image = data.sprites[frame];
     pictureBox2.Image = data.sprites[frame];
     label1.Text       = data.name + " " + (frame + 1) + "/" + data.sprites.Count;
 }
예제 #2
0
        /// -------------------------------------------------------------------------------------------------
        /// <summary>   Parse initialise data. </summary>
        /// -------------------------------------------------------------------------------------------------
        public void ParseIniData()
        {
            spriteframeindex = 0;
            spriteindex      = 0;
            spriteData.Clear();


            string exportfile = ini.GetSettingsString("export", "");
            string file       = ini.GetSettingsString("file", "");

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            if (string.IsNullOrEmpty(exportfile))
            {
                return;
            }

            //load sheet
            Bitmap myBitmap = new Bitmap(file);

            //make byte data store
            byte[] current = new byte[256];

            string code = ";exported sprite data\n";

            foreach (string name in ini.names)
            {
                SpriteData sData = new SpriteData();
                sData.name = name;

                int offsetx = ini.GetSettingsInt(name + "offsetx", 0);
                int offsety = ini.GetSettingsInt(name + "offsety", 0);
                int modx    = ini.GetSettingsInt(name + "modx", 0);
                int mody    = ini.GetSettingsInt(name + "mody", 0);
                int countx  = ini.GetSettingsInt(name + "countx", 1);
                int county  = ini.GetSettingsInt(name + "county", 1);

                int sizex = ini.GetSettingsInt(name + "sizex", 16);
                int sizey = ini.GetSettingsInt(name + "sizey", 16);

                int currectoffsety = offsety;
                int count          = 0;
                for (int cy = 0; cy < county; cy++)
                {
                    int currectoffsetx = offsetx;
                    for (int cx = 0; cx < countx; cx++)
                    {
                        code = code + "; extracted from " + currectoffsetx + "," + currectoffsety + " of sheet\n";

                        Bitmap temp = new Bitmap(sizex, sizey);


                        if (sizex <= 16 && sizey <= 16)
                        {
                            ExtractImage(ref myBitmap, ref current, currectoffsetx, currectoffsety, ref temp, 0, 0);
                            BuildCode(ref code, ref current, name, count);
                        }
                        else
                        {
                            int xlumps = sizex / 16;
                            int ylumps = sizey / 16;

                            for (int ys = 0; ys < ylumps; ys++)
                            {
                                for (int xs = 0; xs < xlumps; xs++)
                                {
                                    ExtractImage(ref myBitmap, ref current, currectoffsetx + (xs * 16), currectoffsety + (ys * 16), ref temp, xs * 16, ys * 16);
                                    BuildCode(ref code, ref current, name + "x" + ys + "y" + xs + "_", count);
                                }
                            }
                        }



                        sData.sprites.Add(temp);
                        pictureBox1.Image = temp;



                        currectoffsetx += modx;
                        count++;
                    }


                    currectoffsety += mody;
                }


                spriteData.Add(sData);
            }

            System.IO.File.WriteAllText(exportfile, code);
        }