Example #1
0
    private void CreateElementsForTileMap(XmlReader tilemap)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(tilemap.ReadOuterXml());

        XmlNode imageNode = doc.ChildNodes[0];

        float scaleInverse = Futile.resourceScaleInverse;

        //XMLNode imageNode = tilemap.children[0] as XMLNode;
        string sourceString = imageNode.Attributes["name"].Value.ToString();

        tileWidth = Convert.ToInt32(imageNode.Attributes["tilewidth"].Value.ToString());
        tileHeight = Convert.ToInt32(imageNode.Attributes["tileheight"].Value.ToString());

        int firstGID = Convert.ToInt32(imageNode.Attributes["firstgid"].Value.ToString());

        imageNode = imageNode.ChildNodes[0];
        int sourceWidth = Convert.ToInt32(imageNode.Attributes["width"].Value.ToString());
        int sourceHeight = Convert.ToInt32(imageNode.Attributes["height"].Value.ToString());

        int numRows = (sourceHeight / tileHeight);
        int numCols = (sourceWidth / tileWidth);
        int totalTiles = numRows * numCols;

        // load tileset image
        Futile.atlasManager.LoadImage("Atlases/" + sourceString);
        FAtlasElement origElement = Futile.atlasManager.GetElementWithName("Atlases/" + sourceString);

        Vector2 _textureSize = origElement.atlas.textureSize;

        int gid = firstGID;
        for(int i = 0; i < totalTiles; i++) {

            FAtlasElement element = new FAtlasElement();

            string name = "tile_" + gid;

            element.name = name;

            element.isTrimmed = origElement.isTrimmed;

            element.atlas = origElement.atlas;
            element.atlasIndex = i;

            //the uv coordinate rectangle within the atlas
            float frameX = (origElement.uvRect.x * _textureSize.x) - origElement.sourceRect.x + ((i % numCols) * tileWidth);
            float frameY = (-1 * ((origElement.uvRect.y * _textureSize.y) - _textureSize.y + origElement.sourceRect.height)) - origElement.sourceRect.y + ((i / numRows) * tileHeight);

            float frameW = tileWidth;
            float frameH = tileHeight;

            Rect uvRect = new Rect
            (
                frameX/_textureSize.x,
                ((_textureSize.y - frameY - frameH)/_textureSize.y),
                frameW/_textureSize.x,
                frameH/_textureSize.y
            );

            element.uvRect = uvRect;

            element.uvTopLeft.Set(uvRect.xMin,uvRect.yMax);
            element.uvTopRight.Set(uvRect.xMax,uvRect.yMax);
            element.uvBottomRight.Set(uvRect.xMax,uvRect.yMin);
            element.uvBottomLeft.Set(uvRect.xMin,uvRect.yMin);

            //the source size is the untrimmed size
            element.sourcePixelSize.x = tileWidth;
            element.sourcePixelSize.y = tileHeight;

            element.sourceSize.x = element.sourcePixelSize.x * scaleInverse;
            element.sourceSize.y = element.sourcePixelSize.y * scaleInverse;

            //this rect is the trimmed size and position relative to the untrimmed rect
            float rectX = origElement.sourceRect.x;
            float rectY = origElement.sourceRect.y;
            float rectW = tileWidth * scaleInverse;
            float rectH = tileHeight * scaleInverse;

            element.sourceRect = new Rect(rectX,rectY,rectW,rectH);

            _allElementsByName.Add(element.name, element);
            gid++;
        }
    }
Example #2
0
 private void Bar(XmlReader reader)
 {
     reader.Read();
     string foo = reader.ReadOuterXml();
     CError.Compare(foo, "<device xmlns=\"http://www.test.com/\">        <thing>1</thing>    </device>",
         "<device xmlns=\"http://www.test.com/\"><thing>1</thing></device>", "mismatch");
 }
Example #3
0
File: test.cs Project: mono/gert
	void IXmlSerializable.ReadXml (XmlReader reader)
	{
		XmlDocument doc = new XmlDocument ();
		string str = reader.ReadString ();
		try {
			doc.LoadXml (str);
		} catch {
			doc.LoadXml (reader.ReadOuterXml ());
		}
		mFuncXmlNode = (XmlNode) (doc.DocumentElement);
	}