Example #1
0
        static int Main(string[] args)
        {
            String directory = @"..\Resources\";

            if (args.Length == 1)
            {
                directory = args[0];
            }
            else if (args.Length != 0)
            {
                return(Launch(args));
            }

            Console.Clear();
            Helper.Write("SpriteSheet Creator makes sprite sheets from directory.", ConsoleColor.Yellow);
            Helper.Write("v.1.0 - @mihailogazda", ConsoleColor.Yellow);
            Helper.Write("Call with /? for help", ConsoleColor.Magenta);

            arguments = new ProgramArguments();
            PNGFiles  = Helper.GetPNGFilesInDirectory(directory);

            Helper.WriteSUCCESS("\r\nFound files counted: " + PNGFiles.Count);

            Bitmap outputImage;
            Dictionary <string, Rectangle> outputMap;

            //  Pack all in one - try at least
            ImagePacker p      = new ImagePacker();
            int         status = p.PackImage(PNGFiles, pow2, sqrt, maxWidth, maxHeight, split, true, out outputImage, out outputMap);

            if (status == 0)
            {
                //  Success
                Cocos2DMapExporter cm = new Cocos2DMapExporter();
                PngImageExporter   ie = new PngImageExporter();

                cm.Save(outMap, outputMap);
                ie.Save(outImage, outputImage);

                Helper.WriteSUCCESS("Saved " + outImage + " from first try!");
            }
            else
            {
                Helper.Write("\r\nCannot pack in single try.", ConsoleColor.Yellow);

                //  split in two and try that way
                Partitioner part = new Partitioner();
                part.ExportHalf(PNGFiles);

                if (part.success())
                {
                    Helper.WriteSUCCESS("All partitions written.");
                }
                else
                {
                    Helper.WriteError("Not all partitions written.");
                }
            }
Example #2
0
        public void Save(Bitmap image, Dictionary <string, Rectangle> map)
        {
            Cocos2DMapExporter cm = new Cocos2DMapExporter();
            PngImageExporter   ie = new PngImageExporter();

            String oi = index == 0 ? Program.outImage : Path.GetFileNameWithoutExtension(Program.outImage) + index + Path.GetExtension(Program.outImage);
            String om = index == 0 ? Program.outMap : Path.GetFileNameWithoutExtension(Program.outMap) + index + Path.GetExtension(Program.outMap);

            Program.arguments.image = oi;
            Program.arguments.map   = om;

            cm.Save(om, map);
            ie.Save(oi, image);

            Helper.Write("Sheet " + index + " saved to disk!\r\n", ConsoleColor.Cyan);
            ++index;
        }