【发布时间】:2014-07-25 17:19:28
【问题描述】:
好吧,进入我的演员班 我正在将演员绘制为图像
caja = new Texture("minerjpg/box.jpg");
miCaja =new TextureRegion(caja,Constants.size,Constants.size);
public void draw(Batch batch, float parentAlpha)
{
int x=Constants.startX+Constants.size*matPosX;
int y=Constants.startY+Constants.size*matPosY;
batch.draw(miCaja, x, y);
}
所以如果我需要改变演员形象,我只是改变 caja img。 但如果我需要一个白人作为演员 我应该用什么?? 如何将 int 传递给纹理或纹理区域??
public boolean Intento(){
setDisarmed(true);
if(isBomb()){
dispose();
caja = new Texture("minerjpg/bomb.jpg");
miCaja =new TextureRegion(caja,Constants.size,Constants.size);
return false;
}else{
dispose();
int aux=logicaJuego.recorrer(matPosX, matPosY);
System.out.println(aux);
//here should be pass from int to texture -_-
//I have read a lot of manual, but noone explained it
caja = new Texture(imageNumero);
miCaja =new TextureRegion(caja,Constants.size,Constants.size);
return true;
}
}
【问题讨论】:
-
不太清楚你在问什么。没有采用 int 的 Texture 构造函数。如果您有多个要选择的纹理,请创建一个纹理数组并调用
miCaja.setTexture(texturesArray[imageNumero]);。根据您使用 TextureRegion 的方式,您可能还需要致电miCaja.setRegion(0,0,1,1);。 -
顺便说一下,如果经常调用这个方法,你不应该创建新的纹理对象,因为它会使游戏卡顿。在
create()方法中加载场景的所有纹理。并且永远不要在其自身上调用dispose()——这将是不必要的崩溃的重要来源。只有对象的所有者才能对其调用 dispose。 -
好吧,我只是想,改变有这个演员的形象,把它换成一些数字,而不是改变演员的位置或其他特征。
-
所以我不应该在创建方法之外创建纹理?? dispose 是内部方法,用于销毁显卡上的图像。
-
不,因为那样你会无缘无故地一遍又一遍地加载纹理。它会导致你的游戏卡顿。此外,您应该使用 TextureAtlas 以避免进行多次绘制调用。 TextureAtlas 将许多 TextureRegions 存储在单个 Texture 上,因此可以在一次绘制调用中绘制所有精灵。每个绘图调用都会占用大量 CPU 时间,因此您需要尽量减少它们。