2013-08-28 3 views
0

저는 90 프레임의 애니메이션을 가지고 있으며이를 미니 크래프트 허드에 표시하고 싶습니다. 여기에 내가 지금 사용하는 코드입니다 :OpenGL - 텍스처가 너무 많습니다.

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을 만드는 것입니다 .. !! 텍스처를 미리로드하고 같은 방식으로 표시하려면 어떻게해야합니까?

답변

0

getResourceLocation (String resourceLocation) 메서드에서 클래스의 개인 정적 최종 해시 맵을 사용할 수 있습니다. 다음과 같이하십시오 :

private static ResourceLocation getResourceLocation(String resourceLocation) { 
    ResourceLocation myRes = myHashMap.get(resourceLocation); 

    if (myRes == null) { 
     myRes = new ResourceLocation(resourceLocation); 
     myHashMap.put(resourceLocation, myRes); 
    } 

    return myRes; 
} 

필요에 따라 리소스를 캐시합니다. 필요한 메모리가 필요한지 확인하십시오!