Android Open Source - misty Texture Manager






From Project

Back to project page misty.

License

The source code is released under:

MIT License

If you think the Android project misty 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

package com.misty.graphics.textures;
//from   w ww. ja v  a2 s.c  o  m
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.misty.utils.Assets;

public class TextureManager
{
  private static final Object lock = new Object();
  private static final Map<String, Texture> loadedTextures = new HashMap<String, Texture>();
  
  public static void loadTextures(String... texturesPath)
  {
    for (String texturePath : texturesPath)
    {
      TextureManager.loadTexture(texturePath);
    }
  }
  
  public static Texture loadTexture(String texturePath)
  {
    Texture result = new Texture(texturePath);
    
    synchronized (TextureManager.lock)
    {
      TextureManager.loadedTextures.put(texturePath, result);
    }
    
    return result;
  }
  
  public static void reloadTextures()
  {
    synchronized (TextureManager.lock)
    {
      Collection<Texture> textures = TextureManager.loadedTextures.values();
      
      for (Texture texture : textures)
      {
        texture.reload();
      }
    }
  }
  
  public static Texture getTexture(String texturePath)
  {
    Texture result = null;
    
    synchronized (TextureManager.lock)
    {
      if (TextureManager.loadedTextures.containsKey(texturePath))
      {
        result = TextureManager.loadedTextures.get(texturePath);
      }
      else
      {
        result = TextureManager.loadTexture(texturePath);
      }
    }
    
    return result;
  }
  
  protected static Bitmap getBitmap(String texturePath)
  {
    Bitmap result = null;
    InputStream inputStream = null;
    
    try
    {
      inputStream = Assets.getInputStream(texturePath);
      result = BitmapFactory.decodeStream(inputStream);
    }
    catch (Exception e)
    {
    }
    finally
    {
      Assets.close(inputStream);
    }
    
    return result;
  }
}




Java Source Code List

com.misty.audio.AudioManager.java
com.misty.debug.FPS.java
com.misty.debug.TimeCounter.java
com.misty.graphics.Animation.java
com.misty.graphics.Camera.java
com.misty.graphics.CollisionGrid.java
com.misty.graphics.Renderer.java
com.misty.graphics.ScreenResolution.java
com.misty.graphics.textures.TextureManager.java
com.misty.graphics.textures.Texture.java
com.misty.input.TouchEvent.java
com.misty.kernel.Alarm.java
com.misty.kernel.Engine.java
com.misty.kernel.Misty.java
com.misty.kernel.Process.java
com.misty.math.Rectangle.java
com.misty.math.Utils.java
com.misty.math.Vector.java
com.misty.utils.Assets.java