首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AndEngine字体问题

AndEngine字体问题
EN

Stack Overflow用户
提问于 2014-01-02 07:02:30
回答 1查看 721关注 0票数 0

我在学习和学习。我正在使用下面的代码显示“嗨”字

代码语言:javascript
复制
        package com.example.textfontexample;
    import org.andengine.engine.camera.Camera;
    import org.andengine.engine.options.EngineOptions;
    import org.andengine.engine.options.ScreenOrientation;
    import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
    import org.andengine.entity.scene.Scene;
    import org.andengine.entity.scene.background.Background;
    import org.andengine.entity.text.Text;
    import org.andengine.opengl.font.Font;
    import org.andengine.opengl.font.FontFactory;
    import org.andengine.opengl.texture.Texture;
    import org.andengine.opengl.texture.TextureOptions;
    import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
    import org.andengine.ui.activity.SimpleBaseGameActivity;
    import org.andengine.util.color.Color;

    import android.util.DisplayMetrics;
    import android.view.Display;
    import android.view.WindowManager;

    public class myactivity extends SimpleBaseGameActivity
    {

     private final int CAMERA_WIDTH = 320;
     private final int CAMERA_HEIGHT = 480;

     private Camera  m_Camera;
     private Scene  m_Scene;

     private Font  font;
     private Text  text;

     @Override
     public EngineOptions onCreateEngineOptions()
     {
      m_Camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
      EngineOptions en = new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(
        CAMERA_WIDTH, CAMERA_HEIGHT), m_Camera);

      return en;
     }

     @Override
     protected void onCreateResources()
     {
        //determine the density
     WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
     Display display = windowManager.getDefaultDisplay();
     DisplayMetrics displayMetrics = new DisplayMetrics();
     display.getMetrics(displayMetrics);
     int density = (int)(displayMetrics.density);

     //scale desired size 25 by density
         int fontSize = (int) (25 * density);
      font = FontFactory.createFromAsset(this.getFontManager(), this.getTextureManager(), 1024, 1024, this.getAssets(),
        "times.ttf", fontSize, true, android.graphics.Color.BLACK);
      font.load();



    //Texture fontTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
    //font = new Font(fontTexture, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL), fontSize, true, Color.WHITE);
    //mEngine.getTextureManager().loadTexture(fontTexture);
    //mEngine.getFontManager().loadFont(font);

     }

     @Override
     protected Scene onCreateScene()
     {
      m_Scene = new Scene();
      m_Scene.setBackground(new Background(Color.WHITE));

      text = new Text(0, 0, font, "Hello Android", this.getVertexBufferObjectManager());
      m_Scene.attachChild(text);

      text.setPosition(CAMERA_WIDTH/2 - (text.getWidth()/2), CAMERA_HEIGHT/2 - (text.getHeight()/2));
      return m_Scene;
     }

    }

它显示的字体如下

正如你所看到的,像素在上浆,字体看起来太难看了。如何显示正确的字体文本,哪些像素没有字符串?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-03 05:11:27

代码语言:javascript
复制
   FontFactory.setAssetBasePath("font/");
        BitmapTextureAtlas fontTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
        mFont = FontFactory.createFromAsset(this.getFontManager(), fontTexture, this.getAssets(), "Droid.ttf", 48, true, android.graphics.Color.WHITE);
    fontTexture.load();
     mFont.load();

在这种模式下试试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20877947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档