Java OpenGL-纹理太多
我有一个90帧的动画,我想在minecraft hud上显示它。 下面是我现在使用的代码:Java OpenGL-纹理太多,java,opengl,minecraft,Java,Opengl,Minecraft,我有一个90帧的动画,我想在minecraft hud上显示它。 下面是我现在使用的代码: String CType = "Target"; int CSpeed = 30; int fast = 0; public int CenterRoteryCounter = 0; @ForgeSubscribe public void CenterRotery(RenderGameOverlayEvent.Post event){ //========Resolution======== res =
String CType = "Target";
int CSpeed = 30;
int fast = 0;
public int CenterRoteryCounter = 0;
@ForgeSubscribe
public void CenterRotery(RenderGameOverlayEvent.Post event){
//========Resolution========
res = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
int width = res.getScaledWidth();
int height = res.getScaledHeight();
//========Resolution========+
if(CenterRoteryCounter == 90){CenterRoteryCounter = 0;}
if(CenterRoteryCounter < 10){
this.mc.renderEngine.func_110577_a(new ResourceLocation("CenterRotery/"+CType+"000" + CenterRoteryCounter + ".png"));
}else{if(CenterRoteryCounter < 100){
this.mc.renderEngine.func_110577_a(new ResourceLocation("CenterRotery/"+CType+"00" + CenterRoteryCounter + ".png"));
}else{
this.mc.renderEngine.func_110577_a(new ResourceLocation("CenterRotery/"+CType+"0" + CenterRoteryCounter + ".png"));
}
}
drawTexturedModalRect((width/2)-44, (height/2)-37, 0, 0, 250, 250);
mc.func_110434_K().func_110577_a(Gui.field_110324_m);
if((fast % CSpeed)==0){CenterRoteryCounter++;}fast++;
}
String CType=“Target”;
int-CSpeed=30;
int fast=0;
public int CenterRoteryCounter=0;
@伪造订阅
public void CenterRotery(RenderGameOverlayEvent.Post事件){
//==========分辨率========
res=新的ScaledResolution(mc.gameSettings、mc.displayWidth、mc.displayHeight);
int width=res.getScaledWidth();
int height=res.getScaledHeight();
//==========分辨率========+
如果(CenterRoteryCounter==90){CenterRoteryCounter=0;}
如果(中心计数器<10){
此.mc.renderEngine.func_110577_a(新资源位置(“CenterRotery/”+CType+“000”+CenterRoteryCounter+”.png));
}else{if(CenterRoteryCounter<100){
此.mc.renderEngine.func_110577_a(新资源位置(“CenterRotery/”+CType+“00”+CenterRoteryCounter+”.png));
}否则{
这个.mc.renderEngine.func_110577_a(新资源位置(“CenterRotery/”+CType+“0”+CenterRoteryCounter+”.png));
}
}
drawTexturedModalRect((宽度/2)-44,(高度/2)-37,0,0,250,250);
mc.func_110434_K().func_110577_a(Gui.field_110324_m);
如果((fast%CSpeed)==0){CenterRoteryCounter++;}fast++;
}
但正如您所看到的,这将每秒创建约30个新资源位置。。!!
如何预加载纹理并以相同的方式显示它们?您只需在方法getResourceLocation(String resourceLocation)中使用类中的私有静态最终Hashmap即可。比如:
private static ResourceLocation getResourceLocation(String resourceLocation) {
ResourceLocation myRes = myHashMap.get(resourceLocation);
if (myRes == null) {
myRes = new ResourceLocation(resourceLocation);
myHashMap.put(resourceLocation, myRes);
}
return myRes;
}
它将按需缓存您的资源。只需确定所需的内存量即可