Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. Couldn't load asset 'cars2.png, com.badlogic.gdx.graphics.g2d.TextureAtlas',Libgdx
  2. com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: cars2.png
  3.  
  4. import com.badlogic.gdx.Gdx;
  5.  
  6.  
  7. public class Constants {
  8. public static final float VIEWPORT_WIDTH = 9.0F;
  9. public static final float VIEWPORT_HEIGHT = 16.0F;
  10. public static final String TEXTURE_ATLAS_OBJECTS = "cars2.png";
  11.  
  12. }
  13.  
  14. import com.badlogic.gdx.Gdx;
  15. import com.badlogic.gdx.assets.AssetDescriptor;
  16. import com.badlogic.gdx.assets.AssetErrorListener;
  17. import com.badlogic.gdx.assets.AssetManager;
  18. import com.badlogic.gdx.graphics.g2d.TextureAtlas;
  19. import com.badlogic.gdx.utils.Disposable;
  20. import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
  21. import com.splitspark.roadfightc.Constants;
  22. import com.badlogic.gdx.graphics.Texture;
  23. import com.badlogic.gdx.graphics.Texture.TextureFilter;
  24.  
  25.  
  26. public class Assets implements Disposable, AssetErrorListener {
  27. public static final String TAG = Assets.class.getName();
  28. public static final Assets instance = new Assets();
  29. private AssetManager assetManager;
  30. public AssetMaincar maincar;
  31. public EnemyCar1 enemyCar1;
  32. public EnemyCar2 enemyCar2;
  33. public EnemyCar3 enemyCar3;
  34. public Truck truck;
  35. //public AssetLevelDecoration levelDecoration;
  36.  
  37.  
  38. private Assets() {}
  39.  
  40. public void init (AssetManager assetManager) {
  41. this.assetManager = assetManager;
  42. // set asset manager error handler
  43. assetManager.setErrorListener(this);
  44. // load texture atlas
  45. assetManager.load(Constants.TEXTURE_ATLAS_OBJECTS, TextureAtlas.class);
  46. //start loading assets and wait until finished
  47. assetManager.finishLoading();
  48. Gdx.app.debug(TAG, "# of assets loaded: " + assetManager.getAssetNames().size);
  49. for (String a : assetManager.getAssetNames())
  50. Gdx.app.debug(TAG, "asset: " + a);
  51.  
  52. TextureAtlas atlas = assetManager.get(Constants.TEXTURE_ATLAS_OBJECTS);
  53.  
  54. // enable texture filtering for pixel smoothing
  55.  
  56. for (Texture t : atlas.getTextures())
  57. t.setFilter(TextureFilter.Linear, TextureFilter.Linear);
  58.  
  59. // create game resource objects
  60. maincar = new AssetMaincar(atlas);
  61. enemyCar1 = new EnemyCar1(atlas);
  62. enemyCar2 = new EnemyCar2(atlas);
  63. enemyCar3 = new EnemyCar3(atlas);
  64. truck = new Truck(atlas);
  65. //levelDecoration = new AssetLevelDecoration(atlas);
  66. }
  67. @Override
  68. public void dispose () {
  69. assetManager.dispose();
  70. }
  71.  
  72.  
  73. @Override
  74. public void error (AssetDescriptor filename, Throwable throwable) {
  75. Gdx.app.error(TAG, "Couldn't load asset '"
  76. + filename + "'", (Exception) throwable);
  77. }
  78.  
  79. public class AssetMaincar {
  80. public final AtlasRegion car;
  81. public AssetMaincar (TextureAtlas atlas) {
  82. car = atlas.findRegion("main_car");
  83. }
  84. }
  85.  
  86. public class EnemyCar1 {
  87. public final AtlasRegion encar1;
  88. public EnemyCar1 (TextureAtlas atlas) {
  89. encar1 = atlas.findRegion("enemy_car_1");
  90. }
  91. }
  92.  
  93. public class EnemyCar2 {
  94. public final AtlasRegion encar2;
  95. public EnemyCar2 (TextureAtlas atlas) {
  96. encar2 = atlas.findRegion("enemy_car_2");
  97. }
  98. }
  99.  
  100. public class EnemyCar3 {
  101. public final AtlasRegion encar3;
  102. public EnemyCar3 (TextureAtlas atlas) {
  103. encar3 = atlas.findRegion("enemy_car_3");
  104. }
  105. }
  106.  
  107. public class Truck {
  108. public final AtlasRegion truck;
  109. public Truck (TextureAtlas atlas) {
  110. truck = atlas.findRegion("truck");
  111. }
  112. }
  113.  
  114. public class ManholeOpen {
  115. public final AtlasRegion manhole;
  116. public ManholeOpen (TextureAtlas atlas) {
  117. manhole = atlas.findRegion("manhole");
  118. }
  119. }
  120.  
  121. public class ManholeClosed {
  122. public final AtlasRegion manholec;
  123. public ManholeClosed (TextureAtlas atlas) {
  124. manholec = atlas.findRegion("manholec");
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement