在基于LibGDX的项目中,在为HTML项目(使用GWT)编译项目时,隐藏的' .DT_Store'资产文件夹中的文件将不会被部署,但仍会被引用。这导致:
" .DT_Store文件"找不到
当你打开页面时。
答案 0 :(得分:0)
您需要过滤掉您不想包含在部署中的文件。
此解决方案可应用于您要排除的任何其他文件。
<。>在.gwt.xml文件中,添加以下标记:<set-configuration-property name="gdx.assetfilterclass" value="com.my.Package.DefaultAssetFilter" />
<set-configuration-property name="gdx.assetpath" value="../android/assets" />
在HTML项目中添加一个类:
package com.my.Package;
import com.badlogic.gdx.backends.gwt.preloader.AssetFilter;
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
public class DefaultAssetFilter implements AssetFilter {
private String extension (String file) {
String name = file;
int dotIndex = name.lastIndexOf('.');
if (dotIndex == -1) return "";
return name.substring(dotIndex + 1);
}
@Override
public boolean accept (String file, boolean isDirectory) {
if (isDirectory && file.endsWith(".svn")) return false;
if (isDirectory && file.endsWith(".bundle")) return false;
if (file.endsWith(".DS_Store")) return false;
return true;
}
@Override
public AssetType getType (String file) {
String extension = extension(file).toLowerCase();
if (isImage(extension)) return AssetType.Image;
if (isAudio(extension)) return AssetType.Audio;
if (isText(extension)) return AssetType.Text;
return AssetType.Binary;
}
private boolean isImage (String extension) {
return extension.toLowerCase().equals("jpg") || extension.toLowerCase().equals("jpeg") || extension.toLowerCase().equals("png") || extension.toLowerCase().equals("bmp") || extension.toLowerCase().equals("gif");
}
private boolean isText (String extension) {
return extension.toLowerCase().equals("json") || extension.toLowerCase().equals("xml") || extension.equals("txt") || extension.equals("glsl")
|| extension.equals("fnt") || extension.equals("pack") || extension.equals("obj") || extension.equals("atlas")
|| extension.equals("g3dj");
}
private boolean isAudio (String extension) {
return extension.toLowerCase().equals("mp3") || extension.toLowerCase().equals("ogg") || extension.toLowerCase().equals("wav");
}
@Override
public String getBundleName (String file) {
return "assets";
}
}