public AsImage(AsTexture texture)
            : base(texture.getFrame() != null ? texture.getFrame().width : texture.getWidth(), texture.getFrame() != null ? texture.getFrame().height : texture.getHeight(), 0xffffff, texture.getPremultipliedAlpha())
        {
            bool pma = texture.getPremultipliedAlpha();

            mVertexData.setTexCoords(0, 0.0f, 0.0f);
            mVertexData.setTexCoords(1, 1.0f, 0.0f);
            mVertexData.setTexCoords(2, 0.0f, 1.0f);
            mVertexData.setTexCoords(3, 1.0f, 1.0f);
            mTexture                = texture;
            mSmoothing              = AsTextureSmoothing.BILINEAR;
            mVertexDataCache        = new AsVertexData(4, pma);
            mVertexDataCacheInvalid = true;
        }
Beispiel #2
0
        private void parseFontXml(AsXML fontXml)
        {
            float       scale = mTexture.getScale();
            AsRectangle frame = mTexture.getFrame();

            mName       = fontXml.elements("info").attribute("face");
            mSize       = AsGlobal.parseFloat(fontXml.elements("info").attribute("size")) / scale;
            mLineHeight = AsGlobal.parseFloat(fontXml.elements("common").attribute("lineHeight")) / scale;
            mBaseline   = AsGlobal.parseFloat(fontXml.elements("common").attribute("base")) / scale;
            if (fontXml.elements("info").attribute("smooth").ToString() == "0")
            {
                setSmoothing(AsTextureSmoothing.NONE);
            }
            if (mSize <= 0)
            {
                AsGlobal.trace("[Starling] Warning: invalid font size in '" + mName + "' font.");
                mSize = mSize == 0.0f ? 16.0f : mSize * -1.0f;
            }
            AsXMLList __charElements_ = fontXml.elements("chars").elements("_char");

            if (__charElements_ != null)
            {
                foreach (AsXML charElement in __charElements_)
                {
                    int         id       = (int)(AsGlobal.parseInt(charElement.attribute("id")));
                    float       xOffset  = AsGlobal.parseFloat(charElement.attribute("xoffset")) / scale;
                    float       yOffset  = AsGlobal.parseFloat(charElement.attribute("yoffset")) / scale;
                    float       xAdvance = AsGlobal.parseFloat(charElement.attribute("xadvance")) / scale;
                    AsRectangle region   = new AsRectangle();
                    region.x      = AsGlobal.parseFloat(charElement.attribute("x")) / scale + frame.x;
                    region.y      = AsGlobal.parseFloat(charElement.attribute("y")) / scale + frame.y;
                    region.width  = AsGlobal.parseFloat(charElement.attribute("width")) / scale;
                    region.height = AsGlobal.parseFloat(charElement.attribute("height")) / scale;
                    AsTexture    texture    = AsTexture.fromTexture(mTexture, region);
                    AsBitmapChar bitmapChar = new AsBitmapChar(id, texture, xOffset, yOffset, xAdvance);
                    addChar(id, bitmapChar);
                }
            }
            AsXMLList __kerningElements_ = fontXml.elements("kernings").elements("kerning");

            if (__kerningElements_ != null)
            {
                foreach (AsXML kerningElement in __kerningElements_)
                {
                    int   first  = (int)(AsGlobal.parseInt(kerningElement.attribute("first")));
                    int   second = (int)(AsGlobal.parseInt(kerningElement.attribute("second")));
                    float amount = AsGlobal.parseFloat(kerningElement.attribute("amount")) / scale;
                    if (mChars.containsKey(second))
                    {
                        getChar(second).addKerning(first, amount);
                    }
                }
            }
        }