Android Open Source - TreeFrogEngine Sprite






From Project

Back to project page TreeFrogEngine.

License

The source code is released under:

MIT License

If you think the Android project TreeFrogEngine 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.discretesoftworks.framework;
/*from   www.  ja v  a 2  s . c  o  m*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Sprite extends GriddedObject{
  
  private int[] frames;
  private float maskWidth, maskHeight;
  
  public Sprite(Bitmap source, int frames){
    super(0,0,0,2,2);
    generateSprite(source,frames);
  }
  
  public Sprite(final int resourceId, int frames){
    super(0,0,0,2,2);
    Context context = (Context)GameRenderer.s_instance.getGame();
    final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;   // No pre-scaling
    final Bitmap source = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
    generateSprite(source,frames);
  }
  
  public void generateSprite(Bitmap source, int frames){
    // Read in the resource
        Bitmap[] bitmaps = new Bitmap[frames];
        this.frames = new int[frames];
        this.maskWidth = source.getHeight();
        this.maskHeight = source.getWidth()/frames;
        int width = (int)maskWidth;
        int height = (int)maskHeight;
        for (int i = 0; i < bitmaps.length; i++){
          bitmaps[i] = Bitmap.createBitmap(source,i*width,0,width,height);
          this.frames[i] = MyGLRenderer.loadTexture(bitmaps[i]); // May need to call s_instance
        }
        setMaskWidth(width);
        setMaskHeight(height);
        setDimensions(width,height);
  }
  
  public void setManualDimensions(int width, int height){
    setWidth(width);
    setLength(height);
  }
  
  public int getSprite(int imageSingle){
    return frames[imageSingle];
  }
  
  public int getSpriteLength(){
    return frames.length;
  }
  
  public float getMaskWidth(){
    return maskWidth;
  }
  
  public float getMaskHeight(){
    return maskHeight;
  }
  
  public void setMask(float width, float height){
    this.maskWidth = width;
    this.maskHeight = height;
  }
  
  public void setMaskWidth(int width){
    this.maskWidth = width;
  }
  
  public void setMaskHeight(int height){
    this.maskHeight = height;
  }
}




Java Source Code List

com.discretesoftworks.OUYAframework.OuyaGameController.java
com.discretesoftworks.OUYAframework.OuyaGame.java
com.discretesoftworks.TestGame.Floor.java
com.discretesoftworks.TestGame.Player.java
com.discretesoftworks.TestGame.Pointer.java
com.discretesoftworks.TestGame.TestController.java
com.discretesoftworks.TestGame.TestGame.java
com.discretesoftworks.framework.AndroidGame.java
com.discretesoftworks.framework.Assets.java
com.discretesoftworks.framework.Directional.java
com.discretesoftworks.framework.GameController.java
com.discretesoftworks.framework.GameFont.java
com.discretesoftworks.framework.GameObject.java
com.discretesoftworks.framework.GameRenderer.java
com.discretesoftworks.framework.GriddedObject.java
com.discretesoftworks.framework.ModelLoader.java
com.discretesoftworks.framework.MovingObject.java
com.discretesoftworks.framework.MyGLRenderer.java
com.discretesoftworks.framework.MyGLSurfaceView.java
com.discretesoftworks.framework.NumericalMatrix.java
com.discretesoftworks.framework.Pair.java
com.discretesoftworks.framework.Path.java
com.discretesoftworks.framework.Pool.java
com.discretesoftworks.framework.RaggedDictionary.java
com.discretesoftworks.framework.RenderModel.java
com.discretesoftworks.framework.Sprite.java
com.discretesoftworks.framework.Terrain.java
com.discretesoftworks.framework.TextDisplay.java
com.discretesoftworks.framework.TextHolder.java
com.discretesoftworks.framework.View.java
com.discretesoftworks.networking.NetworkGameController.java
com.discretesoftworks.networking.Writer.java