Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Couldn't load asset 'cars2.png, com.badlogic.gdx.graphics.g2d.TextureAtlas',Libgdx
- com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: cars2.png
- import com.badlogic.gdx.Gdx;
- public class Constants {
- public static final float VIEWPORT_WIDTH = 9.0F;
- public static final float VIEWPORT_HEIGHT = 16.0F;
- public static final String TEXTURE_ATLAS_OBJECTS = "cars2.png";
- }
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.assets.AssetDescriptor;
- import com.badlogic.gdx.assets.AssetErrorListener;
- import com.badlogic.gdx.assets.AssetManager;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas;
- import com.badlogic.gdx.utils.Disposable;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
- import com.splitspark.roadfightc.Constants;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.Texture.TextureFilter;
- public class Assets implements Disposable, AssetErrorListener {
- public static final String TAG = Assets.class.getName();
- public static final Assets instance = new Assets();
- private AssetManager assetManager;
- public AssetMaincar maincar;
- public EnemyCar1 enemyCar1;
- public EnemyCar2 enemyCar2;
- public EnemyCar3 enemyCar3;
- public Truck truck;
- //public AssetLevelDecoration levelDecoration;
- private Assets() {}
- public void init (AssetManager assetManager) {
- this.assetManager = assetManager;
- // set asset manager error handler
- assetManager.setErrorListener(this);
- // load texture atlas
- assetManager.load(Constants.TEXTURE_ATLAS_OBJECTS, TextureAtlas.class);
- //start loading assets and wait until finished
- assetManager.finishLoading();
- Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size);
- for (String a : assetManager.getAssetNames())
- Gdx.app.debug(TAG, "asset: " + a);
- TextureAtlas atlas = assetManager.get(Constants.TEXTURE_ATLAS_OBJECTS);
- // enable texture filtering for pixel smoothing
- for (Texture t : atlas.getTextures())
- t.setFilter(TextureFilter.Linear, TextureFilter.Linear);
- // create game resource objects
- maincar = new AssetMaincar(atlas);
- enemyCar1 = new EnemyCar1(atlas);
- enemyCar2 = new EnemyCar2(atlas);
- enemyCar3 = new EnemyCar3(atlas);
- truck = new Truck(atlas);
- //levelDecoration = new AssetLevelDecoration(atlas);
- }
- @Override
- public void dispose () {
- assetManager.dispose();
- }
- @Override
- public void error (AssetDescriptor filename, Throwable throwable) {
- Gdx.app.error(TAG, "Couldn't load asset '"
- + filename + "'", (Exception) throwable);
- }
- public class AssetMaincar {
- public final AtlasRegion car;
- public AssetMaincar (TextureAtlas atlas) {
- car = atlas.findRegion("main_car");
- }
- }
- public class EnemyCar1 {
- public final AtlasRegion encar1;
- public EnemyCar1 (TextureAtlas atlas) {
- encar1 = atlas.findRegion("enemy_car_1");
- }
- }
- public class EnemyCar2 {
- public final AtlasRegion encar2;
- public EnemyCar2 (TextureAtlas atlas) {
- encar2 = atlas.findRegion("enemy_car_2");
- }
- }
- public class EnemyCar3 {
- public final AtlasRegion encar3;
- public EnemyCar3 (TextureAtlas atlas) {
- encar3 = atlas.findRegion("enemy_car_3");
- }
- }
- public class Truck {
- public final AtlasRegion truck;
- public Truck (TextureAtlas atlas) {
- truck = atlas.findRegion("truck");
- }
- }
- public class ManholeOpen {
- public final AtlasRegion manhole;
- public ManholeOpen (TextureAtlas atlas) {
- manhole = atlas.findRegion("manhole");
- }
- }
- public class ManholeClosed {
- public final AtlasRegion manholec;
- public ManholeClosed (TextureAtlas atlas) {
- manholec = atlas.findRegion("manholec");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement