あなたがここに達成しようとしている何がlibGdxで少し複雑です。しかし、ボールの上に別のスプライトオブジェクトとしてテキストを描画しているので、あなたのアプローチは間違っています。
これを達成する正しい手順は、テキストをテクスチャに描画し、テクスチャをボールにマップしてバインドすることです。
手順は、4つの部分に分けることができ
-
- モデルにテクスチャをマッピングし、フォントの生成およびテキストを描画スプライトバッチ
- セットアップフレームバッファオブジェクト
- セットアップ
- モデルのレンダリング
注釈として、他のテクスチャを使用することができますリアルタイムでテキストを更新したくない場合は、事前に作成したテクスチャを任意のテキストで簡単に使用することができます。次のように
コードは - フォント生成およびフレームバッファオブジェクト
//Create a new SpriteBatch object
batch = new SpriteBatch();
//Generate font
FreeTypeFontGenerator generator = new
FreeTypeFontGenerator(Gdx.files.internal("font/Lato-Bold.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new
FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
parameter.color = com.badlogic.gdx.graphics.Color.WHITE;
parameter.magFilter = Texture.TextureFilter.Linear; // used for resizing quality
parameter.minFilter = Texture.TextureFilter.Linear;
generator.scaleForPixelHeight(10);
//Get bitmap font
BitmapFont aFont = generator.generateFont(parameter);
aFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear,
Texture.TextureFilter.Linear);
//Generate new framebuffer object of 128x128 px. This will be our texture
FrameBuffer lFb = new FrameBuffer(Pixmap.Format.RGBA4444,128,128,false);
スプライトバッチのセットアップ
//Set the correct resolution for drawing to the framebuffer
lFb.begin();
Gdx.gl.glViewport(0,0,128,128);
Gdx.gl.glClearColor(1f, 1f, 1f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Matrix4 lm = new Matrix4();
//Set the correct projection for the sprite batch
lm.setToOrtho2D(0,0,128,128);
batch.setProjectionMatrix(lm);
最後にテキストを描画するの設定
テクスチャ
batch.begin();
aFont.draw(batch,"Goal!",64,64);
batch.end();
lFb.end();
レンダリングモデル
//Generate the material to be applied to the ball
//Notice here how we use the FBO's texture as the material base
Material lMaterial = new Material(TextureAttribute.createDiffuse(lFb.getColorBufferTexture()));
//Since I do not have a sphere model, I'll just create one with the newly
//generated material
ballModel = mb.createSphere(1.0f,1.0f,1.0f,8,8,lMaterial,
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates);
//Finally instantiate an object of the model
ballInstance = new ModelInstance(ballModel);
にモデルをテクスチャ地図
mBatch.begin(mCamera);
mBatch.render(ballInstance);
mBatch.end();
//Rotate the ball along the y-axis
ballInstance.transform.rotate(0.0f,1.0f,0.0f,0.5f);
結果 -

同じマトリックス上に別のエンティティとしてテキストを描画しています。あなたがbasketBallなどのために使用しているテクスチャビットマップにテキストを描画するためにこれを実現する1つの方法は、球形になります。 – Qamar