Game Development Reference
In-Depth Information
public PixmapFormat getFormat() {
return format;
}
public void dispose() {
bitmap.recycle();
}
}
All we need to do is store the Bitmap instance that we wrap, along with its format, which is
stored as a PixmapFormat enumeration value, as defined in Chapter 3. Additionally, we implement
the required methods of the Pixmap interface so that we can query the width and height of the
Pixmap , as well as its format, and ensure that the pixels can be dumped from RAM. Note that
the Bitmap member is package private, so we can access it in AndroidGraphics , which we'll
implement now.
AndroidGraphics: Serving Our Drawing Needs
The Graphics interface we designed in Chapter 3 is also lean and mean. It will draw pixels, lines,
rectangles, and Pixmap s to the framebuffer. As discussed, we'll use a Bitmap as our framebuffer
and direct all drawing calls to it via a Canvas . It is also responsible for creating Pixmap instances
from asset files. Therefore, we'll also need another AssetManager . Listing 5-14 shows the code
for our implementation of the interface, AndroidGraphics , with commentary.
Listing 5-14. AndroidGraphics.java; Implementing the Graphics Interface
package com.badlogic.androidgames.framework.impl;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import com.badlogic.androidgames.framework.Graphics;
import com.badlogic.androidgames.framework.Pixmap;
public class AndroidGraphics implements Graphics {
AssetManager assets;
Bitmap frameBuffer;
Canvas canvas;
Paint paint;
Rect srcRect= new Rect();
Rect dstRect= new Rect();
 
Search WWH ::




Custom Search