2012-02-26 9 views
3

深刻な低レベルのデバッグを掘り下げる前に、私はスプライト上にテキストを描画するという概念に問題があるかどうか疑問に思っていました。 は、私はこれが行われているが、どこにもありません気付いAPIの例を通じてトロール。すべてのテキストスプライトは、私はほとんど描かれしようとしている何かを見ることができるPNG画像 にプリレンダリングされているが、唯一の任意のアドバイスは私がのユーザーポスト渡って来た 乾杯Andengine - スプライト上にテキストを描画する

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); 
     } 
    } 
} 

答えて

3

をいただければ幸いです白い斑点や線 を表示されますそれはあなた(と私は)で、行うことを求めているんどのように見える「SpriteButton」、:あなたはButtonSpriteと呼ばれるビルトインAndEngineクラスの言及に気付くでしょうコメントで http://www.andengine.org/forums/tutorials/spritebutton-class-t7440.html

が、私それを参照する実際のコードを見ていない。それはAndEngineソースの別のブランチであってもよいです。

SpriteButtonをインスタンス化する前に、フォントとテクスチャ領域を作成して読み込む必要があることに注意してください。

私はまたSpriteButtonが回転をどのように処理するかをウェルに探しています。翻訳(ユーザータッチ経由)は正常に機能しているようです。

+0

ご回答いただきありがとうございます。それは良い答えです。私は、実際には最終的に私自身のスプライトボタンを作ってしまうので、この質問を忘れませんでした。 しかし、あなたは正しいですので、私は答えとしてこれをマーキングしています。私の問題は、Windowsでフォントとして使用できる.TTFファイルは、andEngine Textクラスで動作すると仮定していました。しかし、それはかなり台無しだった。私は別のフォントを使用して終了し、すべてが期待どおりに働いた。歓声 – Justin

+0

@Justinあなたはテキストをスプライトに従うために使ったクラスとメソッドを投稿できますか? – rasen58

関連する問題