0

我有一个 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 = 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++;
}

但正如您所看到的,这每秒会创建约 30 个新的 ResourceLocations ..!!如何预加载纹理并以相同的方式显示它们?

4

1 回答 1

0

您可以在方法 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;
}

它将按需缓存您的资源。只要确定所需的必要内存量即可!

于 2013-08-28T12:47:39.920 回答