Andengine - 在精灵上/内部绘制文本

3

在我深入进行一些严肃的低级调试之前,我想知道在精灵上绘制文本这个概念是否存在问题。 在浏览API示例时,我注意到没有任何地方使用此功能。所有文本精灵都是预先渲染为PNG文件。 我几乎可以看到某些东西正在尝试被绘制,但只出现白色斑点或线条。 如果有建议,请告诉我。 谢谢

public class Tile extends Sprite {
    private static BitmapTextureAtlas mBitmapTextureAtlas;
    private static TextureRegion mBoxTextureRegion;
    private static BitmapTextureAtlas mFontTexture;
    private static Font mFont;
    String letter;
    private Text mText;
    public int score;

    public Tile(String letter, int score, float x, float y, float width, float height) {
        super(x, y, width, height, mBoxTextureRegion);
        this.letter = letter;
        this.score = score;
    }

    public static void loadResources(Context context, Engine mEngine) {
        Tile.mFontTexture = new BitmapTextureAtlas(512, 512, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        Tile.mFont = FontFactory.createFromAsset(Tile.mFontTexture, context, "Arial Rounded MT.ttf", 64, true, Color.WHITE);

        mEngine.getTextureManager().loadTexture(Tile.mFontTexture);
        mEngine.getFontManager().loadFont(Tile.mFont);

        Tile.mBitmapTextureAtlas = new BitmapTextureAtlas(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

        Tile.mBoxTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(Tile.mBitmapTextureAtlas, context, "rect3761.png", 0, 0);

        mEngine.getTextureManager().loadTexture(Tile.mBitmapTextureAtlas);

    }

    public void draw(GraphicScene scene) {
        if (letter != null) {
            this.mText = new Text(50, 50, Tile.mFont, letter, HorizontalAlign.CENTER);
            // this.mText.setBlendFunction(GL10.GL_SRC_ALPHA,
            // GL10.GL_ONE_MINUS_SRC_ALPHA);
            // this.mText.setAlpha(0.5f);
            this.attachChild(this.mText);
            scene.attachChild(this);
        }
    }
}
1个回答

3
我确实发现了一个名为“SpriteButton”的用户帖子,它看起来可以实现你(和我)想要做的事情,网址是: http://www.andengine.org/forums/tutorials/spritebutton-class-t7440.html 在评论中,你会注意到有提到一个内置的AndEngine类叫做ButtonSprite,但我没有看到任何实际引用它的代码。它可能在AndEngine源码的另一个分支中。
请注意,在实例化SpriteButton之前,您需要创建和加载字体以及纹理区域。
我还在研究SpriteButton处理旋转的效果如何。通过用户触摸进行的位移似乎可以正常工作。

谢谢你的回复。那是一个很好的答案。事实上,最终我确实自己制作了一个精灵按钮,因此忘记了这个问题。 但你是对的,所以我将把这个标记为答案。我的问题实际上是,我假设在Windows中可以用作字体的任何.TTF文件都可以与andEngine Text类一起使用。但结果非常混乱。最后我使用了不同的字体,一切都按预期工作了。干杯 - Justin
@Justin,你能否发布一下你用来使文本跟随精灵的类和方法? - rasen58

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接