private void writeAnimToXml(XmlWriter aXmlWriter, Animation aAnimation) throws IOException
    {
         aXmlWriter.writeEntity("anim");
         aXmlWriter.writeAttribute("name", aAnimation.getName());
         aXmlWriter.writeAttribute("loops", aAnimation.getLoops());

         int backupIndex = aAnimation.getCurrentCellIndex();
         aAnimation.setCurrentCellIndex(0);
         AnimationCell cell = aAnimation.getCurrentCell();
         while(cell !=  null)
         {
            aXmlWriter.writeEntity("cell");
            aXmlWriter.writeAttribute("index", aAnimation.getCurrentCellIndex());
            aXmlWriter.writeAttribute("delay", cell.getDelay());

            ArrayList<GraphicObject> graphicList = cell.getGraphicList();
            for (int i=0; i<graphicList.size(); ++i)
            {
                SpriteGraphic graphic = (SpriteGraphic)graphicList.get(i);
                CustomNode node = cell.nodeForGraphic(graphic);
                aXmlWriter.writeEntity("spr");
                aXmlWriter.writeAttribute("name", node.getFullPathName());
                aXmlWriter.writeAttribute("x", graphic.getRect().x + graphic.getRect().width/2);
                aXmlWriter.writeAttribute("y", graphic.getRect().y + graphic.getRect().height/2);                                
                aXmlWriter.writeAttribute("z", cell.zOrderOfGraphic(graphic));                                
                
                if (graphic.getAngle() != 0)
                    aXmlWriter.writeAttribute("angle", graphic.getAngle());
                if (graphic.isFlippedV())
                    aXmlWriter.writeAttribute("flipV", graphic.isFlippedV() ? 1 : 0);
                if (graphic.isFlippedH())
                    aXmlWriter.writeAttribute("flipH", graphic.isFlippedH() ? 1 : 0);
                
                aXmlWriter.endEntity();
            }

            aXmlWriter.endEntity();

            cell = aAnimation.getNextCell();
         }

         aXmlWriter.endEntity();
    }