Before I delve into some serious lowlevel debugging, I was just wondering if there was any problem with the concept of drawing text on a sprite.
Trawling through the API examples I noticed there is nowhere this is being done. All text sprites are pre-rendered into pngs
I can almost see something trying to be drawn, but only appears white flecks or lines
Any advice would be appreciated
Cheers
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);
}
}
}
I did come across user post of a “SpriteButton”, which looks like it does what you (and I) are looking to do, at:
http://www.andengine.org/forums/tutorials/spritebutton-class-t7440.html
In the comments you’ll notice a mention of a built-in AndEngine class called a ButtonSprite, but I have not seen any actual code that refers to it. It may be in another branch of the AndEngine source.
Note that you’ll need to create and load a font, as well as a textureregion before instantiating a SpriteButton.
I am also looking into how well the SpriteButton handles rotation. Translation (via user touch) seems to work okay.