public class GdxGraphics extends Object implements Disposable
GdxGraphics class has a similar interface to the FunGraphics class used for the
INF1 course given at the University of Applied Sciences School in Sion.
The main objective of this implementation is to provide a simple, yet powerful,
set of graphics primitives used for the projects that take place in this course.
Comments are welcome !| Modifier and Type | Field and Description |
|---|---|
protected Color |
backgroundColor |
protected OrthographicCamera |
camera |
protected Texture |
circleTex |
protected Color |
currentColor |
protected OrthographicCamera |
fixedCamera |
protected BitmapFont |
font |
protected Texture |
logoTex |
protected SpriteBatch |
spriteBatch |
| Constructor and Description |
|---|
GdxGraphics(ShapeRenderer shapeRenderer,
SpriteBatch spriteBatch,
OrthographicCamera camera) |
| Modifier and Type | Method and Description |
|---|---|
void |
begin()
Begin drawing.
|
void |
beginCustomRendering()
Begin custom rendering.
|
void |
clear()
Clear the screen using the
backgroundColor. |
void |
clear(Color c)
Clear the screen with a given
Color. |
void |
clearPixel(float x,
float y)
Clear a pixel and set it to the
backgroundColor. |
void |
clearPixel(float x,
float y,
Color c)
Clear a pixel and set it to a custom
Color. |
void |
dispose()
Should be called to release all the resources that have been allocated in
GdxGraphics. |
void |
draw(Texture texture,
float[] spriteVertices,
int offset,
int count)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height,
float u,
float v,
float u2,
float v2)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
boolean flipX,
boolean flipY)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
boolean flipX,
boolean flipY)
Draw on the SpriteBatch.
|
void |
draw(Texture texture,
float x,
float y,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Draw on the SpriteBatch.
|
void |
draw(TextureRegion region,
float x,
float y)
Draw on the SpriteBatch.
|
void |
draw(TextureRegion region,
float width,
float height,
Affine2 transform)
Draw on the SpriteBatch.
|
void |
draw(TextureRegion region,
float x,
float y,
float width,
float height)
Draw on the SpriteBatch.
|
void |
draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)
Draw on the SpriteBatch.
|
void |
draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation,
boolean clockwise)
Draw on the SpriteBatch.
|
void |
drawAlphaPicture(float posX,
float posY,
float alpha,
BitmapImage img)
Draw a picture at a specific position with transparency (alpha).
|
void |
drawAlphaPicture(float posX,
float posY,
float angle,
float scale,
float alpha,
BitmapImage img)
Draw a picture at a specific position with transparency (alpha).
|
void |
drawAlphaPicture(Vector2 pos,
float alpha,
BitmapImage img)
Draw a picture at a specific position with transparency (alpha).
|
void |
drawAntiAliasedCircle(float centerX,
float centerY,
float radius,
Color c)
Draw an anti-aliased circle (with nice border without jaggies).
|
void |
drawBackground(BitmapImage t,
float i,
float j)
Draw an image in the background that will not move with the camera.
|
void |
drawBackground(Texture t,
float i,
float j)
Draws a texture in background that will not move with the camera.
|
void |
drawCircle(float centerX,
float centerY,
float radius)
Draw an empty (non filled) circle.
|
void |
drawCircle(float centerX,
float centerY,
float radius,
Color c)
Draw an empty (non filled) circle with a custom color.
|
void |
drawFilledBorderedCircle(float centerX,
float centerY,
float radius,
Color inner,
Color outer)
Draw a filled circle with a border.
|
void |
drawFilledCircle(float centerX,
float centerY,
float radius,
Color c)
Draw a filled circle with a custom color.
|
void |
drawFilledPolygon(Polygon p,
Color c)
Draw a filled
Polygon. |
void |
drawFilledRectangle(float x,
float y,
float w,
float h,
float angle)
Draw a filled rectangle.
|
void |
drawFilledRectangle(float x,
float y,
float w,
float h,
float angle,
Color c)
Draw a filled rectangle with a custom color.
|
void |
drawFPS()
Draw frame per second (FPS) information in the bottom left corner of the
screen.
|
void |
drawFPS(Color c)
Draw frame per second (FPS) information in the bottom left corner of the
screen using a custom color.
|
void |
drawLine(float p1x,
float p1y,
float p2x,
float p2y)
Draw a line with the current
currentColor. |
void |
drawLine(float p1x,
float p1y,
float p2x,
float p2y,
Color c)
Draws a line with a specific color.
|
void |
drawPicture(float posX,
float posY,
BitmapImage bitmap)
Draw a picture at a specific position.
|
void |
drawPolygon(Polygon p)
Draw an empty (not filled)
Polygon. |
void |
drawRectangle(float x,
float y,
float w,
float h,
float angle)
Draw an empty (not filled) rectangle.
|
void |
drawSchoolLogo()
Draw the the school logo in the bottom right corner of the screen.
|
void |
drawSchoolLogoUpperRight()
Draw the school logo in the upper right corner of the screen.
|
void |
drawShader()
Draw the current assigned shader.
|
void |
drawShader(float shaderTime)
Draw the current assigned shader.
|
void |
drawShader(int posX,
int posY,
float shaderTime)
Request shader rendering that passes an uniform value with the current
rendering location.
|
void |
drawString(float posX,
float posY,
String str)
Draw a text at a specified position.
|
void |
drawString(float posX,
float posY,
String str,
BitmapFont f)
Draw a text with a specific font at a specified position.
|
void |
drawString(float posX,
float posY,
String str,
BitmapFont f,
int align)
Draw a text with a specific font at a specified position.
|
void |
drawString(float posX,
float posY,
String str,
int align)
Draw a text at a specified position.
|
void |
drawStringCentered(float posY,
String str)
Draw a text in the middle of the screen.
|
void |
drawStringCentered(float posY,
String str,
BitmapFont f)
Draw a text in the middle of the screen with a specific font.
|
void |
drawTransformedPicture(float posX,
float posY,
float angle,
float scale,
BitmapImage bitmap)
Draws a picture at a specific position with a scale and an angle.
|
void |
drawTransformedPicture(float posX,
float posY,
float angle,
float width,
float height,
BitmapImage bitmap)
Draw a stretched picture at a specific position.
|
void |
drawTransformedPicture(float posX,
float posY,
float centerX,
float centerY,
float angle,
float scale,
BitmapImage bitmap)
Draw a picture at a specific position with a custom center of rotation.
|
void |
end()
End drawing.
|
void |
endCustomRendering()
Begin custom rendering.
|
OrthographicCamera |
getCamera()
Get the current camera.
|
int |
getScreenHeight()
Get the height of the rendering surface.
|
int |
getScreenWidth()
Get the width of the rendering surface.
|
ShaderRenderer |
getShaderRenderer()
Get the shader renderer.
|
void |
moveCamera(float x,
float y)
Move the camera to a fixed position.
|
void |
moveCamera(float interest_x,
float interest_y,
float world_width,
float world_height)
Point the camera to the center of interest limited by the game size.
|
void |
resetBlend()
Restore the default blending function on the SpriteBatch.
|
void |
resetCamera()
Resets the camera at its original location, in the center of the screen.
|
void |
sbFlush()
Flush the current SpriteBatch.
|
Color |
sbGetColor()
Get the current color of the SpriteBatch.
|
void |
sbSetColor(Color col)
Set the current color of the SpriteBatch.
|
void |
sbSetColor(float r,
float g,
float b,
float a)
Set the current color of the SpriteBatch.
|
void |
scroll(float dx,
float dy)
Translate the camera by a value on the X and Y axes.
|
void |
setBackgroundColor(Color c)
Set the background color used when pixels are cleared.
|
void |
setBlendFunction(int srcFunc,
int dstFunc)
Set blending function on the SpriteBatch.
|
void |
setColor(Color c)
Set the current color
currentColor used for graphics drawing. |
void |
setPenWidth(float width)
A very simple way to change line width for shape operators (line, ...).
|
void |
setPixel(float x,
float y)
Set the color of a pixel using the current color
currentColor. |
void |
setPixel(float x,
float y,
Color c)
Sets the color of a pixel using a custom
Color. |
void |
setShader(String s)
Set a shader to be drawn.
|
void |
setShader(String s,
int width,
int height)
Set a shader to be drawn with a specific size.
|
void |
setShaderRenderer(ShaderRenderer shaderRenderer)
Set a custom shader renderer.
|
void |
zoom(float factor)
Zooms in and out the camera.
|
protected final Texture logoTex
protected final Texture circleTex
protected SpriteBatch spriteBatch
protected OrthographicCamera camera
protected OrthographicCamera fixedCamera
protected BitmapFont font
protected Color currentColor
protected Color backgroundColor
public GdxGraphics(ShapeRenderer shapeRenderer, SpriteBatch spriteBatch, OrthographicCamera camera)
public void dispose()
GdxGraphics. Normally called automatically.dispose in interface Disposablepublic void drawFPS()
Color.WHITE color is used.drawFPS(Color)public void drawFPS(Color c)
c - the text colorpublic void drawSchoolLogo()
drawSchoolLogoUpperRight()public void drawSchoolLogoUpperRight()
drawSchoolLogo()public void setPenWidth(float width)
width - the width of the pen to use as from nowpublic int getScreenHeight()
public int getScreenWidth()
public void clear()
backgroundColor.clear(Color)public void begin()
Game2D before
ch.hevs.gdx2d.desktop.PortableApplication#onGraphicRender(GdxGraphics).public void end()
Game2D before
ch.hevs.gdx2d.desktop.PortableApplication#onGraphicRender(GdxGraphics).public void clear(Color c)
Color.c - The color to clear the screen withclear()public void setColor(Color c)
currentColor used for graphics drawing.c - the new color to usepublic void setPixel(float x,
float y)
currentColor.x - the x coordinate of the pixely - the y coordinate of the pixelsetPixel(float, float, Color)public void setPixel(float x,
float y,
Color c)
Color.
The currentColor is not modified.x - the X coordinate of the pixely - the Y coordinate of the pixelc - the new Color of the pixelsetPixel(float, float)public void setBackgroundColor(Color c)
c - the new background color to usepublic void clearPixel(float x,
float y)
backgroundColor.x - the X coordinate of the pixely - the Y coordinate of the pixelclearPixel(float, float, Color)public void clearPixel(float x,
float y,
Color c)
Color.
The backgroundColor is not modified.x - the X coordinate of the pixely - the Y coordinate of the pixelclearPixel(float, float)public void drawLine(float p1x,
float p1y,
float p2x,
float p2y)
p1x - start coordinate Xp1y - start coordinate Yp2x - end coordinate Xp2y - end coordinate Ypublic void drawLine(float p1x,
float p1y,
float p2x,
float p2y,
Color c)
P(p1x, p1y) and ends at P(p1x, p1y).
The currentColor is not modified.p1x - start coordinate Xp1y - start coordinate Yp2x - end coordinate Xp2y - end coordinate Yc - the color of the linepublic void drawRectangle(float x,
float y,
float w,
float h,
float angle)
x - X position of the center of the rectangley - Y position of the center of the rectanglew - width of the rectangle, in pixelh - height of the rectangle, in pixelangle - rotation of the rectangle, in degreesdrawFilledRectangle(float, float, float, float, float, Color)public void drawFilledRectangle(float x,
float y,
float w,
float h,
float angle)
x - X position of the center of the rectangley - Y position of the center of the rectanglew - width of the rectangle, in pixelh - height of the rectangle, in pixelangle - rotation of the rectangle, in degreesdrawFilledRectangle(float, float, float, float, float, Color)public void drawFilledRectangle(float x,
float y,
float w,
float h,
float angle,
Color c)
currentColor is not modified.x - X position of the center of the rectangley - Y position of the center of the rectanglew - width of the rectangle, in pixelh - height of the rectangle, in pixelangle - rotation of the rectangle, in degreesc - the color to fill the rectangle withpublic void drawCircle(float centerX,
float centerY,
float radius,
Color c)
currentColor is not modified.centerX - center X position of the circlecenterY - center Y position of the circleradius - radius of the circle, in pixelc - the color to fill the circle withpublic void drawCircle(float centerX,
float centerY,
float radius)
centerX - center X position of the circlecenterY - center Y position of the circleradius - radius of the circle, in pixeldrawCircle(float, float, float, Color)public void drawAntiAliasedCircle(float centerX,
float centerY,
float radius,
Color c)
currentColor is not modified.centerX - center X position of the circlecenterY - center Y position of the circleradius - radius of the circle, in pixelc - the color to fill the circle withpublic void drawFilledCircle(float centerX,
float centerY,
float radius,
Color c)
centerX - center X position of the circlecenterY - center Y position of the circleradius - radius of the circle, in pixelc - the color to fill the circle withpublic void drawFilledBorderedCircle(float centerX,
float centerY,
float radius,
Color inner,
Color outer)
public void drawString(float posX,
float posY,
String str)
posX - left position of the textposY - top position of the textstr - the text to display on the screendrawString(float, float, String, BitmapFont, int)public void drawString(float posX,
float posY,
String str,
BitmapFont f)
posX - left position of the textposY - Y top position of the textstr - the text to display on the screenf - the custom font to usepublic void drawString(float posX,
float posY,
String str,
int align)
posX - left, right or center position of the textposY - Y top position of the textstr - the text to display on the screenalign - left, center or right alignedpublic void drawString(float posX,
float posY,
String str,
BitmapFont f,
int align)
posX - left, right or center position of the textposY - Y top position of the textstr - the text to display on the screenf - the custom font to usealign - left, center or right alignedpublic void drawStringCentered(float posY,
String str)
posY - centered Y position of the textstr - the text to displaypublic void drawStringCentered(float posY,
String str,
BitmapFont f)
posY - centered Y position of the textstr - the text to displayf - the custom font to usepublic void drawBackground(BitmapImage t, float i, float j)
t - the image to drawi - X coordinate in the screen spacej - Y coordinate in the screen spacepublic void drawBackground(Texture t, float i, float j)
t - the texture to drawi - X coordinate of the center of the texture, in the screen spacej - Y coordinate of the center of the texture, in the screen spacepublic void drawPicture(float posX,
float posY,
BitmapImage bitmap)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spacebitmap - the image to drawpublic void drawTransformedPicture(float posX,
float posY,
float angle,
float scale,
BitmapImage bitmap)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spaceangle - the rotation angle, in degreescale - scale of the image to draw (1 is not scaled)bitmap - the image to drawpublic void drawTransformedPicture(float posX,
float posY,
float angle,
float width,
float height,
BitmapImage bitmap)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spaceangle - the rotation angle, in degreewidth - the width of the resulting image (which will be scaled for display)height - the height of the resulting imagebitmap - the image to drawpublic void drawTransformedPicture(float posX,
float posY,
float centerX,
float centerY,
float angle,
float scale,
BitmapImage bitmap)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spacecenterX - X position of the rotation centercenterY - Y position of the rotation centerangle - the rotation angle, in degreescale - scale of the image to draw (1 is not scaled)bitmap - the image to drawpublic void drawAlphaPicture(Vector2 pos, float alpha, BitmapImage img)
pos - the Vector2 position to draw the imagealpha - transparency value (0.0 is transparent, 1.0 is opaque)img - the image to drawpublic void drawAlphaPicture(float posX,
float posY,
float alpha,
BitmapImage img)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spacealpha - transparency value (0.0 is transparent, 1.0 is opaque)img - the image to drawdrawAlphaPicture(Vector2, float, BitmapImage)public void drawAlphaPicture(float posX,
float posY,
float angle,
float scale,
float alpha,
BitmapImage img)
posX - X coordinate in the screen spaceposY - Y coordinate in the screen spaceangle - the rotation angle, in degreescale - scale of the image to draw (1 is not scaled)alpha - transparency value (0.0 is transparent, 1.0 is opaque)img - the image to drawdrawAlphaPicture(Vector2, float, BitmapImage)public void drawPolygon(Polygon p)
Polygon.p - the polygon to drawpublic void drawFilledPolygon(Polygon p, Color c)
Polygon.p - the polygon to drawc - the color to fill the polygon withpublic OrthographicCamera getCamera()
OrthographicCamerapublic void moveCamera(float x,
float y)
x - X position of the cameray - Y position of the camerapublic void moveCamera(float interest_x,
float interest_y,
float world_width,
float world_height)
interest_x - X position of the center of interestinterest_y - Y position of the center of interestworld_width - max width of the gameworld_height - max height of the gamepublic void resetCamera()
public void scroll(float dx,
float dy)
dx - displacement along the x axis, can be positive or negativedy - displacement along the y axis, can be positive or negativepublic void zoom(float factor)
factor - zoom factor (1 is the default zoom-level)public void drawShader()
public void drawShader(float shaderTime)
shaderTime - the current time that is passed to the fragment shaderpublic void drawShader(int posX,
int posY,
float shaderTime)
posX - value passed to the shader, might be discardedposY - value passed to the shader, might be discardedshaderTime - value passed to the shader, might be discardedpublic void setShader(String s)
s - the path of the shader filepublic void setShader(String s, int width, int height)
s - the path of the shader fileheight - height of the texture to draw the shader onwidth - width of the texture to draw the shader onpublic ShaderRenderer getShaderRenderer()
public void setShaderRenderer(ShaderRenderer shaderRenderer)
shaderRenderer - the shader rendererpublic void setBlendFunction(int srcFunc,
int dstFunc)
srcFunc - source blending functiondstFunc - destination blending functionresetBlend()public void resetBlend()
public void draw(Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
public void draw(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
public void draw(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
public void draw(Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2)
public void draw(Texture texture, float x, float y)
public void draw(Texture texture, float x, float y, float width, float height)
public void draw(Texture texture, float[] spriteVertices, int offset, int count)
public void draw(TextureRegion region, float x, float y)
public void draw(TextureRegion region, float x, float y, float width, float height)
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise)
public void draw(TextureRegion region, float width, float height, Affine2 transform)
public Color sbGetColor()
public void sbSetColor(float r,
float g,
float b,
float a)
r - redg - greenb - bluea - alphapublic void sbSetColor(Color col)
col - the colorpublic void sbFlush()
public void beginCustomRendering()
public void endCustomRendering()
Copyright © 2014-2016 gdx2d - https://github.com/hevs-isi/gdx2d