【问题标题】:How to use Font and Text in andEngine?如何在andEngine中使用字体和文本?
【发布时间】:2012-07-16 13:24:50
【问题描述】:

我就是这样尝试的:

fontTextureAtlas = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
font = FontFactory.createFromAsset(fontTextureAtlas,this,"times.ttf",45f,true,Color.WHITE);
getEngine().getTextureManager().loadTexture(fontTextureAtlas);

然后,在代码中:

Text text = new Text(10,10, font,"Some text");
scene.attachChild(text);

我看到的都是这样的:

我也尝试使用new Font(fontTextureAtlas,Typeface.DEFAULT,45f,true,Color.WHITE);来初始化font,但结果几乎一样。

有谁知道我做错了什么?

【问题讨论】:

    标签: android andengine


    【解决方案1】:

    尝试在getEngine().getTextureManager().loadTexture(fontTextureAtlas); 之后添加font.load();

    如果不行,试试

    getEngine().getFontManager().loadFont(font);
    

    【讨论】:

    • 没有load() 方法,但我找到了reload()。好吧,没有黑块了,但我也看不到任何字母:i.imgur.com/YPvLf.png
    • @LemuelHogben 那就试试getEngine().getFontManager().loadFont(font);
    【解决方案2】:

    这对我有用

    FontFactory.SetAssetBasePath("fontfolder/");
    
    mFont = FontFactory.createFromAsset(mEngine.getFontManager(),
                mEngine.getTextureManager(), 256, 256, TextureOptions.BILINEAR,
                activity.getAssets(), "QUARTZMS.TTF", 32f, true,
                Color.YELLOW_ARGB_PACKED_INT);
        mFont.load();
    

    那我就加mText = new Text(25, 25, mFont, "Some Text",getVertexBufferObjectManager());

    【讨论】:

      【解决方案3】:

      我在 andengine 中写了一篇关于文本的博文,这可能对http://stuartmct.co.uk/2012/07/16/andengine-creating-and-using-text/有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-12
        • 1970-01-01
        • 1970-01-01
        • 2012-07-02
        • 2020-11-22
        • 2023-03-21
        相关资源
        最近更新 更多