Game Development Reference
In-Depth Information
ï?® Graphics.drawLine() method is analogous to the Graphics.drawPixel()
method. We specify the start point and endpoint of the line, along with a
color. Any portion of the line that is outside the framebuffer's raster will
be ignored.
The
ï?® Graphics.drawRect() method draws a rectangle to the framebuffer.
The (x,y) specifies the position of the rectangle's top-left corner in the
framebuffer. The arguments width and height specify the number of pixels
in x and y, and the rectangle will fill starting from (x,y). We fill downward in y.
The color argument is the color that is used to fill the rectangle.
The
The
ï?® Graphics.drawPixmap() method draws rectangular portions of a Pixmap
to the framebuffer. The (x,y) coordinates specify the top-left corner's position
of the Pixmap 's target location in the framebuffer. The arguments srcX and
srcY specify the corresponding top-left corner of the rectangular region
that is used from the Pixmap , given in the Pixmap is own coordinate system.
Finally, srcWidth and srcHeight specify the size of the portion that we take
from the Pixmap .
Finally, the
Graphics.getWidth() and Graphics.getHeight() methods return
the width and height of the framebuffer in pixels.
All of the drawing methods except Graphics.clear() will automatically perform blending
for each pixel they touch, as outlined in the previous section. We could disable blending on
a case-by-case basis to speed up the drawing somewhat, but that would complicate our
implementation. Usually, we can get away with having blending enabled all the time for simple
games like Mr. Nom.
The Pixmap interface is given in Listing 3-7.
ï?®
Listing 3-7. The Pixmap Interface
package com.badlogic.androidgames.framework;
import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
public interface Pixmap {
public int getWidth();
public int getHeight();
public PixmapFormat getFormat();
public void dispose();
}
We keep it very simple and immutable, as the compositing is done in the framebuffer:
ï?® Pixmap.getWidth() and Pixmap.getHeight() methods return the width
and the height of the Pixmap in pixels.
The
The
ï?® Pixmap.getFormat() method returns the PixelFormat that the Pixmap is
stored with in RAM.
Search WWH ::




Custom Search