Android Open Source - TreeFrogEngine Game Font






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;
// ww w .j  av a2s.c om
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;

// Parses and Holds a PNG font and its sprites
public class GameFont {
  
  private Sprite[] fontLetters;
  private String letters;
  public Sprite holder;
  
  public GameFont(int resourceId, String str){
    letters = str;
    
    int len = letters.length();
    fontLetters = new Sprite[len];
    
    /* Pixel marker RGB: 254, 183, 213 */
    int colorMarkerOne = Color.rgb(1,255,1);
    int colorMarkerTwo = Color.rgb(255,1,1);
    
    Context context = (Context)GameRenderer.s_instance.getGame();
    final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;   // No pre-scaling
    final Bitmap fontBitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    int height = 0;
    while (fontBitmap.getPixel(0,height) != colorMarkerTwo){
      height += 1;
    }
    int start = 0;
    int end = 0;
    int x = 0;
    int y = height + 2;
    
    
    for (int i = 0; i < len; i++){
      start = end;
      while (fontBitmap.getPixel(start, y) != colorMarkerOne){
        start += 1;
        if (start >= fontBitmap.getWidth() - 2){
          start = 0;
          y += height + 1;
        }
      }
      end = start+1;
      while (fontBitmap.getPixel(end, y) != colorMarkerTwo){
        end += 1;
        if (end >= fontBitmap.getWidth() - 2){
          end = 0;
          y += height + 1;
        }
      }
      int manWidth = (end-start)+1;
      int width = 64; // FIX LATER
      Bitmap srcBitmap = Bitmap.createBitmap(fontBitmap,x,y+1,manWidth,height);
      
      Bitmap newBitmap = Bitmap.createBitmap(width, height, config);
      Canvas can = new Canvas(newBitmap);
      //can.drawARGB(FF,FF,FF,FF); //This represents White color
      can.drawBitmap(srcBitmap, 0, 0, null);
      
      //Bitmap newBitmap = Bitmap.createBitmap(srcBitmap,0,0,width,height);
      fontLetters[i] = new Sprite(newBitmap,1);
      fontLetters[i].setMaskWidth(manWidth);
      x += manWidth;
    }
    holder = fontLetters[0];
  }
  
  // Grab the sprite of our particular char
  public Sprite getLetter(char c){
    if (letters.indexOf(c) >= 0)
      return fontLetters[letters.indexOf(c)];
    else
      return fontLetters[0];
  }
  
}




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