Game Development Reference
In-Depth Information
We propose two simple interfaces: Graphics and Pixmap . Let's start with the Graphics interface,
shown in Listing 3-6.
Listing 3-6. The Graphics Interface
package com.badlogic.androidgames.framework;
public interface Graphics {
public static enum PixmapFormat {
ARGB8888 , ARGB4444 , RGB565
}
public Pixmap newPixmap(String fileName, PixmapFormat format);
public void clear( int color);
public void drawPixel( int x, int y, int color);
public void drawLine( int x, int y, int x2, int y2, int color);
public void drawRect( int x, int y, int width, int height, int color);
public void drawPixmap(Pixmap pixmap, int x, int y, int srcX, int srcY,
int srcWidth, int srcHeight);
public void drawPixmap(Pixmap pixmap, int x, int y);
public int getWidth();
public int getHeight();
}
We start with a public static enum called PixmapFormat . It encodes the different pixel formats we
will support. Next, we have the different methods of our Graphics interface:
The
ï?® Graphics.newPixmap() method will load an image given in either JPEG
or PNG format. We specify a desired format for the resulting Pixmap , which is
a hint for the loading mechanism. The resulting Pixmap might have a different
format. We do this so that we can somewhat control the memory footprint of
our loaded images (for example, by loading RGB888 or ARGB8888 images
as RGB565 or ARGB4444 images). The filename specifies an asset in our
application's APK file.
ï?® Graphics.clear() method clears the complete framebuffer with the
given color . All colors in our little framework will be specified as 32-bit
ARGB8888 values ( Pixmap s might, of course, have a different format).
The
The
ï?® Graphics.drawPixel() method will set the pixel at (x,y) in the
framebuffer to the given color . Coordinates outside the screen will be
ignored. This is called clipping .
 
Search WWH ::




Custom Search