If you think the Android project DolphinOES listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright 2014 See AUTHORS file./*fromwww.java2s.com*/
*
* 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.
******************************************************************************/package com.sidereal.dolphinoes.architecture.core.assetload;
import com.badlogic.gdx.assets.AssetLoaderParameters;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.sidereal.dolphinoes.architecture.DolphinOES;
import com.sidereal.dolphinoes.architecture.GameObject;
import com.sidereal.dolphinoes.architecture.GameScene;
import com.sidereal.dolphinoes.architecture.core.Assets;
/** Utility class that makes loading assets using {@link Assets}
* easier.
*
* @author Claudiu Bele */publicclass AssetLoader extends GameObject
{
// region fields
private GameScene nextscene;
private AssetLoadHandler assetLoadHandler;
// endregion fields
// region constructors
/** Creates an asset loader. The params have to be the following:
* <p>
* At index 0, the scene
* <p>
* At index 1, the
*
* @param scene
* @param params */public AssetLoader(GameScene scene, GameScene nextScene)
{
super(scene);
this.assetLoadHandler = new LoadingPercentage(scene);
this.nextscene = nextScene;
}
// endregion constructors
// region methods
@Override
publicvoid update()
{
super.update();
if (DolphinOES.assets.getProgress() == 1
&& assetLoadHandler.canGoToNextScene())
{
goToNextScene();
}
assetLoadHandler.updateProgress(DolphinOES.assets.getProgress());
}
@Override
publicvoid onResize(float x, float y, float oldX, float oldY)
{
assetLoadHandler.onResize(x, y, oldX, oldY);
}
publicvoid setAssetLoadHandler(AssetLoadHandler handler)
{
if(handler == null)
thrownew NullPointerException("AssetLoader.setAssetLoadHandler parameter handler of type AssetLoadHandler is null. One is mandatory for switching scenes");
this.assetLoadHandler = handler;
}
// region Import
public <T> void load(String filepath, Class<T> classType,
AssetLoaderParameters<T> loadParams)
{
load(filepath, classType, Assets.defaultResolver, loadParams);
}
public <T> void load(String filepath, Class<T> classType)
{
load(filepath, classType, Assets.defaultResolver);
}
public <T> void load(String filepath, Class<T> classType,
Class<? extends FileHandleResolver> resolver)
{
DolphinOES.assets.load(filepath, classType, resolver);
}
public <T> void load(String filepath, Class<T> classType,
Class<? extends FileHandleResolver> resolver, AssetLoaderParameters<T> loadParams)
{
DolphinOES.assets.load(filepath, classType, resolver, loadParams);
}
public <T> void load(String generalPath, String[] fileNames,
Class<T> fileType, String extension)
{
load(generalPath, fileNames, fileType, extension,
Assets.defaultResolver);
}
public <T> void load(String generalPath, String[] fileNames,
Class<T> fileType, String extension,
Class<? extends FileHandleResolver> resolver)
{
for (int i = 0; i < fileNames.length; i++)
{
DolphinOES.assets.load(generalPath + fileNames[i] + extension,
fileType, resolver);
}
}
public <T> void load(String generalPath, String[] fileNames,
Class<T> fileType, String extension,
Class<? extends FileHandleResolver> resolver,
AssetLoaderParameters<T> loadParams)
{
for (int i = 0; i < fileNames.length; i++)
{
DolphinOES.assets.load(generalPath + fileNames[i] + extension,
fileType, resolver, loadParams);
}
}
publicfinalvoid goToNextScene()
{
DolphinOES.getInstance().setScreen(nextscene);
}
// endregion
// endregion methods
}