1 /*******************************************************************************
\r
2 * Copyright 2011 See AUTHORS file.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 ******************************************************************************/
17 package com.badlogic.gdx.assets.loaders;
19 import com.badlogic.gdx.assets.AssetDescriptor;
20 import com.badlogic.gdx.assets.AssetLoaderParameters;
21 import com.badlogic.gdx.assets.AssetManager;
22 import com.badlogic.gdx.files.FileHandle;
23 import com.badlogic.gdx.graphics.g2d.ParticleEffect;
24 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
25 import com.badlogic.gdx.utils.Array;
27 /** {@link AssetLoader} to load {@link ParticleEffect} instances. Passing a {@link ParticleEffectParameter} to
28 * {@link AssetManager#load(String, Class, AssetLoaderParameters)} allows to specify an atlas file or an image directory to be
29 * used for the effect's images. Per default images are loaded from the directory in which the effect file is found. */
30 public class ParticleEffectLoader extends SynchronousAssetLoader<ParticleEffect, ParticleEffectLoader.ParticleEffectParameter> {
31 public ParticleEffectLoader (FileHandleResolver resolver) {
36 public ParticleEffect load (AssetManager am, String fileName, FileHandle file, ParticleEffectParameter param) {
37 ParticleEffect effect = new ParticleEffect();
38 if (param != null && param.atlasFile != null)
39 effect.load(file, am.get(param.atlasFile, TextureAtlas.class));
40 else if (param != null && param.imagesDir != null)
41 effect.load(file, param.imagesDir);
43 effect.load(file, file.parent());
48 public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, ParticleEffectParameter param) {
49 Array<AssetDescriptor> deps = null;
50 if (param != null && param.atlasFile != null) {
51 deps = new Array<AssetDescriptor>();
52 deps.add(new AssetDescriptor<TextureAtlas>(param.atlasFile, TextureAtlas.class));
57 /** Parameter to be passed to {@link AssetManager#load(String, Class, AssetLoaderParameters)} if additional configuration is
58 * necessary for the {@link ParticleEffect}. */
59 public static class ParticleEffectParameter extends AssetLoaderParameters<ParticleEffect> {
60 /** Atlas file name. */
61 public String atlasFile;
62 /** Image directory. */
63 public FileHandle imagesDir;