LibGDX/Java에서 게임을 만들고 있습니다. 게임이 시작되면 "assets"폴더에 모든 자산을로드합니다. 이렇게하기 전에 애셋이로드되는 동안 이미지를로드하여로드 이미지로 사용합니다. 데스크톱에서 완벽하게 작동하지만 Android에서 실행하면로드하는 이미지가 표시되고 애셋이로드되기 전에 검은 색 화면이 약 30 초 동안 표시됩니다.Java LibGDX - 화면을로드하기 전에 어리숙 한 긴 기간 동안 검정색 화면이 나타남
LoadingState.java :
public void render(SpriteBatch batch) {
if (!loadedBg) {
GameManager.getInstance().assetManager.finishLoadingAsset("gui/constant/menuBg.png");
loadedBg = true;
}
Texture background = gameManager.assetManager.get("gui/constant/menuBg.png", Texture.class); // Set background image
/* Drawing */
batch.draw(background, 0, 0);
}
Assets.java :
/** Loads all assets from the asset directories */
public void load() {
List<FileHandle> allFiles = new ArrayList<FileHandle>(); // This will contain all the files in all the subdirectories.
for(FileHandle dir : assetDirs) {
allFiles.addAll(FileUtils.listf(dir.path()));
}
for(int i = 0; i < allFiles.size(); i++) {
if(allFiles.get(i).name().startsWith("._")) {
allFiles.remove(i);
}
}
/* Iterate through all the files and load only the png ones */
for(FileHandle f : allFiles) {
if(f.name().endsWith(".png")) { // Found an image file; load it as a texture
manager.load(f.path(), Texture.class);
}
}
}
편집 : 추가 Fileutils의 클래스 FileUtils.java을 다음과 같이
내 현재 코드입니다 :
/** Returns all files from a directory */
public static List<FileHandle> listf(String directoryName) {
FileHandle directory = Gdx.files.internal(directoryName);
List<FileHandle> resultList = new ArrayList<FileHandle>();
// Get all the files from a directory
FileHandle[] fList = directory.list();
resultList.addAll(Arrays.asList(fList));
for (FileHandle file : fList) {
if (file.isDirectory()) {
resultList.addAll(listf(file.path()));
}
}
return resultList;
}
전체적으로 안드로이드 응용 프로그램에 문제가 있습니까? 아니면 LibGDX 만? 나는 개발 초기에이 문제를 안고 있었다. 모든 도움을 주시면 고맙습니다. 감사합니다.
'render()'메소드를 처음으로 반환하기 전에 시간을 많이 소비해야합니다. 무엇을 결정하기 위해 여기에 충분한 코드를 볼 수 없습니다. Apache Commons의 FileUtils인가요, 아니면 자신의 클래스입니까? – Tenfour04
@ Tenfour04 제 코드를 확인해 주셔서 감사합니다. 늦어서 반갑습니다. 체크 아웃 할 FileUtils 클래스를 추가했습니다. 렌더링 클래스는 LoadingState.java 섹션에 표시되는 것으로, 시간이 많이 걸리는 것은 아무 것도 믿지 않습니다. 그렇다면 바탕 화면에 검은 색 화면이 표시 될 수 있기 때문입니다. 현재 상태에서 검은 색 화면은 Android가 아닌 바탕 화면에만 나타납니다. 감사합니다. – Flizzet