private static AnimationChainSave[] _GenerateAnimChain(AnimDef animDef) { // * frame coordinates are in pixels. top-left = 0,0 bottom-right = +X +Y float xStart = animDef.CellXstartIndex * _FrameSize.Width; float yStart = animDef.CellYstartIndex * _FrameSize.Height; AnimationChainSave[] animsList = new AnimationChainSave[_Rotations]; //float currentXStart; float currentYTop; float currentYBottom; float left; AnimationChainSave oneRotAnim; AnimationFrameSave frame; for (ushort iRotation = 0; iRotation < 16; iRotation++) { currentYTop = yStart + iRotation * _FrameSize.Height; currentYBottom = currentYTop + _FrameSize.Height; oneRotAnim = new AnimationChainSave(); // animDef.FramesPerRotation oneRotAnim.Name = animDef.AnimName + '_' + iRotation.ToString(); for (ushort iFrame = 0; iFrame < animDef.FramesPerRotation; iFrame++) { left = xStart + iFrame * _FrameSize.Width; frame = new AnimationFrameSave // (_FramesTexture, 0) { TextureName = _SpriteSheetFileName, TopCoordinate = currentYTop, BottomCoordinate = currentYBottom, LeftCoordinate = left, RightCoordinate = left + _FrameSize.Width, RelativeX = _AllFramesOffset.X, RelativeY = _AllFramesOffset.Y, FrameLength = 0.1f }; //oneRotAnim.Add(frame); oneRotAnim.Frames.Add(frame); } //animsList.Add(oneRotAnim); animsList[iRotation] = oneRotAnim; } return(animsList); }
private void ButGenerate_Click(object sender, RoutedEventArgs e) { #region -- Error checking if (_Project.AnimDefinitons.Count == 0) { MessageBox.Show("Not Anims defined."); return; } if (_Project.SheetFilePath == null) { MessageBox.Show("Enter SpriteSheet image file."); return; } if (!File.Exists(_Project.SheetFilePath)) { MessageBox.Show("SpriteSheet image file not found."); return; } if (_Project.OutputAchxFilePath == null) { MessageBox.Show("Enter Achx output directory."); return; } string achxOutputDir = Path.GetDirectoryName(_Project.OutputAchxFilePath); if (!Directory.Exists(achxOutputDir)) { MessageBox.Show("Achx output directory doesn't exist."); return; } if (DuplicateAnimDefs()) { MessageBox.Show("Two animations can't have a same name."); return; } #endregion -- Error checking END string achxOutputFileNameWOExt = Path.GetFileNameWithoutExtension(_Project.OutputAchxFilePath); // Save project if (CheckBoxSaveProject.IsChecked.Value) { XmlSerializer serializer = new XmlSerializer(typeof(Project)); using (TextWriter writer = new StreamWriter(Path.Combine(achxOutputDir, achxOutputFileNameWOExt + ".achpx"))) { serializer.Serialize( writer, _Project ); } } // Remove whitespace // Convert AnimDefs to zero based indexing var zeroIndexedAnimDefinitons = new AnimDef[_Project.AnimDefinitons.Count]; AnimDef animDefClone; for (int i = 0; i < zeroIndexedAnimDefinitons.Length; i++) { // AnimNames error check if (String.IsNullOrWhiteSpace(_Project.AnimDefinitons[i].AnimName)) { MessageBox.Show("All animations must have name defined.\nName can't be all whitespaces."); return; } // Remove whitespace _Project.AnimDefinitons[i].AnimName = _Project.AnimDefinitons[i].AnimName.Trim(); // Convert AnimDefs to zero based indexing animDefClone = AnimDef.Clone(_Project.AnimDefinitons[i]); animDefClone.CellXstartIndex -= 1; animDefClone.CellYstartIndex -= 1; zeroIndexedAnimDefinitons[i] = animDefClone; } // Create data var animChainList = Generator.Generate( // sheet cell size _Project.SheetCellSize, // sheet file name only (wo path) Path.GetFileName(_Project.SheetFilePath), // _Project.Rotations, // new Offset <float> { X = (float)_Project.FramesOffset.X, Y = (float)_Project.FramesOffset.Y }, // zeroIndexedAnimDefinitons ); // Save achx Generator.SaveAchx( // AnimChainListSave generated by Generator.Generate() animChainList, // - achx // output path achxOutputDir, // output file name wo extension achxOutputFileNameWOExt, // path to sprite sheet Path.GetDirectoryName(_Project.SheetFilePath) ); MessageBox.Show("Achx generation successful"); // Run achx if (CheckBoxOpenAchx.IsChecked.Value) { System.Diagnostics.Process.Start( Path.Combine(achxOutputDir, achxOutputFileNameWOExt + ".achx") ); } }