public class Graphics
extends java.lang.Object
Constructor and Description |
---|
Graphics(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch,
com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch polygonSpriteBatch,
com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer) |
Modifier and Type | Method and Description |
---|---|
void |
clearBlendFunction()
Resets the blend function to its default
|
void |
clearScaling()
Resets scaling back to default values
|
void |
clearShaderProgram()
Clears the
ShaderProgram applied to this instance |
void |
disableBlending()
Disables blending during rendering
|
void |
drawCircle(float centerX,
float centerY,
int radius)
Draws a circle to the window in the current
Color with the set
line height |
void |
drawLineSegment(float x1,
float y1,
float x2,
float y2)
Renders a line segment to the window in the current
Color with
the set line height |
void |
drawNinePatch(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable ninePatchDrawable,
float x,
float y,
float width,
float height)
Draws a
NinePatchDrawable to screen |
void |
drawNinePatch(NinePatch ninePatch,
float x,
float y,
float width,
float height)
Draws a
NinePatch to screen |
void |
drawParticleEffect(ParticleEffect effect)
Draws a
ParticleEffect or PooledParticleEffect to screen |
void |
drawPolygon(float[] vertices)
Draws a polygon to the window in the current
Color |
void |
drawRect(float x,
float y,
float width,
float height)
Renders a rectangle to the window in the current
Color with the
set line height |
void |
drawShape(Shape shape)
Draws an instance of
Shape |
void |
drawSprite(Sprite sprite)
Draws a
Sprite with all transformations applied to this graphics
context |
void |
drawSprite(Sprite sprite,
float x,
float y)
Draws a
Sprite at the given coordinates with all transformations
applied to this graphics context |
void |
drawSpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache spriteCache,
int cacheId)
Draws a
SpriteCache |
void |
drawStage(com.badlogic.gdx.scenes.scene2d.Stage stage)
Draws an instance of a LibGDX
Stage |
void |
drawString(java.lang.String text,
float x,
float y)
Draws a string to the window
|
void |
drawString(java.lang.String text,
float x,
float y,
float targetWidth)
Draws a string to the window, automatically wrapping it within a
specified width
|
void |
drawString(java.lang.String text,
float x,
float y,
float targetWidth,
int horizontalAlign)
Draws a string to the window, automatically wrapping it within a
specified width and aligning it to the left, center or right of the width
|
void |
drawTexture(com.badlogic.gdx.graphics.Texture texture,
float x,
float y)
Draws a texture to this graphics context
|
void |
drawTexture(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
boolean flipY)
Draws a texture to this graphics context
|
void |
drawTexture(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
float width,
float height)
Draws a texture to this graphics context
|
void |
drawTexture(com.badlogic.gdx.graphics.Texture texture,
float x,
float y,
float width,
float height,
boolean flipY) |
void |
drawTextureRegion(TextureRegion textureRegion,
float x,
float y)
Draws a texture region to this graphics context
|
void |
drawTextureRegion(TextureRegion textureRegion,
float x,
float y,
float width,
float height)
Draws a texture region to this graphics context
|
void |
drawTriangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draws a triangle to the window in the current
Color |
void |
enableBlending()
Enables blending during rendering
|
void |
fillCircle(float centerX,
float centerY,
int radius)
Fills a circle to the window in the current
Color |
void |
fillPolygon(float[] vertices,
short[] triangles)
Fills a polygon to the window in the current
Color |
void |
fillRect(float x,
float y,
float width,
float height)
Fills a rectangle to the window in the current
Color |
void |
fillShape(Shape shape)
Fills an instance of
Shape |
void |
fillTriangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draws a triangle to the window in the current
Color |
void |
flush()
Immediately flushes everything rendered rather than waiting until the end
of rendering
|
com.badlogic.gdx.graphics.Color |
getBackgroundColor()
Returns the background
Color |
com.badlogic.gdx.graphics.Color |
getColor()
Returns the
Color to draw shapes with |
com.badlogic.gdx.graphics.g2d.BitmapFont |
getFont()
Returns the
BitmapFont to draw String s with |
int |
getLineHeight()
Returns the line height used
|
com.badlogic.gdx.math.Matrix4 |
getProjectionMatrix() |
float |
getRotation() |
float |
getRotationX() |
float |
getRotationY() |
float |
getScaleX() |
float |
getScaleY() |
com.badlogic.gdx.graphics.glutils.ShaderProgram |
getShaderProgram()
Returns the currently applied
ShaderProgram |
com.badlogic.gdx.graphics.Color |
getTint()
Returns the
Color tint being applied to all draw operations |
float |
getTranslationX() |
float |
getTranslationY() |
float |
getViewportHeight()
Returns the height of the viewport height
|
float |
getViewportWidth()
Returns the width of the viewport width
|
float |
getWindowHeight()
Returns the height of the window height
|
float |
getWindowWidth()
Returns the width of the window width
|
void |
postRender()
Called by mini2Dx after rendering
|
void |
preRender(int gameWidth,
int gameHeight)
Called by mini2Dx before rendering begins
|
Rectangle |
removeClip()
Removes the applied clip
|
void |
removeTint()
Removes the tinting
Color |
void |
rotate(float degrees,
float x,
float y)
Rotates the canvas by the provided degrees around the provided point
|
void |
scale(float scaleX,
float scaleY)
Scales the canvas (multiplies scale value)
|
void |
setBackgroundColor(com.badlogic.gdx.graphics.Color backgroundColor)
Sets the background
Color to be used |
void |
setBlendFunction(int srcFunc,
int dstFunc)
Sets the blend function to be applied
OpenGL Blend Function Cheatsheet
|
void |
setClip(float x,
float y,
float width,
float height)
Sets the graphics context clip.
|
void |
setClip(Rectangle clip)
Sets the graphics context clip.
|
void |
setColor(com.badlogic.gdx.graphics.Color color)
Sets the
Color to draw shapes with |
void |
setFont(com.badlogic.gdx.graphics.g2d.BitmapFont font)
Sets the
BitmapFont to draw String s with |
void |
setLineHeight(int lineHeight)
Sets the line height to be used
|
void |
setRotation(float degrees,
float x,
float y)
Sets the canvas rotation around a provided point
|
void |
setScale(float scaleX,
float scaleY)
Sets the canvas scale
|
void |
setShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram shaderProgram)
Applies a
ShaderProgram to this instance |
void |
setTint(com.badlogic.gdx.graphics.Color tint)
Sets the
Color to apply to draw operations |
void |
setTranslation(float translateX,
float translateY)
Sets the translation coordinates
|
java.lang.String |
toString() |
void |
translate(float translateX,
float translateY)
Moves the graphics context by a certain amount of the X and Y axis
|
public Graphics(com.badlogic.gdx.graphics.g2d.SpriteBatch spriteBatch, com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch polygonSpriteBatch, com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer)
public void preRender(int gameWidth, int gameHeight)
gameWidth
- The current game window widthgameHeight
- The current game window heightpublic void postRender()
public void drawLineSegment(float x1, float y1, float x2, float y2)
Color
with
the set line heightx1
- X coordinate of point Ay1
- Y coordinate of point Ax2
- X coordinate of point By2
- Y coordinate of point Bpublic void drawRect(float x, float y, float width, float height)
Color
with the
set line heightx
- The x coordinate to render aty
- The y coordinate to render atwidth
- The width of the rectangleheight
- The height of the rectanglepublic void fillRect(float x, float y, float width, float height)
Color
x
- The x coordinate to render aty
- The y coordinate to render atwidth
- The width of the rectangleheight
- The height of the rectanglepublic void drawCircle(float centerX, float centerY, int radius)
Color
with the set
line heightcenterX
- The x coordinate of the center of the circlecenterY
- The y coordinate of the center of the circleradius
- The radius of the circlepublic void fillCircle(float centerX, float centerY, int radius)
Color
centerX
- The x coordinate of the center of the circlecenterY
- The y coordinate of the center of the circleradius
- The radius of the circlepublic void drawTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
Color
x1
- The x coordinate of the first pointy1
- The y coordinate of the first pointx2
- The x coordinate of the second pointy2
- The y coordinate of the second pointx3
- The x coordinate of the third pointy3
- The y coordinate of the third pointpublic void fillTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
Color
x1
- The x coordinate of the first pointy1
- The y coordinate of the first pointx2
- The x coordinate of the second pointy2
- The y coordinate of the second pointx3
- The x coordinate of the third pointy3
- The y coordinate of the third pointpublic void drawPolygon(float[] vertices)
Color
vertices
- The vertices of the polygon in format x1,y1,x2,y2,x3,y3,etc.public void fillPolygon(float[] vertices, short[] triangles)
Color
vertices
- The vertices of the polygon in format x1,y1,x2,y2,x3,y3,etc.triangles
- The indices in the vertices parameter that make up the triangles of the polygonpublic void drawString(java.lang.String text, float x, float y)
text
- The String
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atpublic void drawString(java.lang.String text, float x, float y, float targetWidth)
text
- The String
to drawx
- The x coordinate to draw aty
- The y coordinate to draw attargetWidth
- The width to render the String
at. Note: The string
will automatically wrapped if it is longer.public void drawString(java.lang.String text, float x, float y, float targetWidth, int horizontalAlign)
text
- The String
to drawx
- The x coordinate to draw aty
- The y coordinate to draw attargetWidth
- The width to render the String
at. Note: The string
will automatically wrapped if it is longer.horizontalAlign
- The horizontal alignment. Note: Use Align
to retrieve
the appropriate value.public void drawTexture(com.badlogic.gdx.graphics.Texture texture, float x, float y)
texture
- The Texture
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atpublic void drawTexture(com.badlogic.gdx.graphics.Texture texture, float x, float y, boolean flipY)
texture
- The Texture
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atflipY
- True if the texture should be flipped verticallypublic void drawTexture(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height)
texture
- The Texture
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atwidth
- The width to draw the texture (this can stretch/shrink the
texture if not matching the texture's width)height
- The height to draw the texture (this can stretch/shrink the
texture if not matching the texture's height)public void drawTexture(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, boolean flipY)
texture
- The Texture
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atwidth
- The width to draw the texture (this can stretch/shrink the
texture if not matching the texture's width)height
- The height to draw the texture (this can stretch/shrink the
texture if not matching the texture's height)flipY
- True if the texture should be flipped verticallypublic void drawTextureRegion(TextureRegion textureRegion, float x, float y)
textureRegion
- The TextureRegion
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atpublic void drawTextureRegion(TextureRegion textureRegion, float x, float y, float width, float height)
textureRegion
- The TextureRegion
to drawx
- The x coordinate to draw aty
- The y coordinate to draw atwidth
- The width to draw the region (this can stretch/shrink the
texture if not matching the region's width)height
- The height to draw the region (this can stretch/shrink the
texture if not matching the region's height)public void drawShape(Shape shape)
Shape
shape
- The implementation of Shape
to drawpublic void fillShape(Shape shape)
Shape
shape
- The implementation of Shape
to fillpublic void drawSprite(Sprite sprite)
Sprite
with all transformations applied to this graphics
contextsprite
- The Sprite
to drawpublic void drawSprite(Sprite sprite, float x, float y)
Sprite
at the given coordinates with all transformations
applied to this graphics contextsprite
- The Sprite
to drawx
- The x coordinate to render aty
- The y coordinate to render atpublic void drawSpriteCache(com.badlogic.gdx.graphics.g2d.SpriteCache spriteCache, int cacheId)
SpriteCache
spriteCache
- The SpriteCache
to drawcacheId
- The cacheId to drawpublic void drawStage(com.badlogic.gdx.scenes.scene2d.Stage stage)
Stage
stage
- The Stage
to be drawn to screenpublic void drawParticleEffect(ParticleEffect effect)
ParticleEffect
or PooledParticleEffect
to screeneffect
- The effect to be drawnpublic void drawNinePatch(NinePatch ninePatch, float x, float y, float width, float height)
NinePatch
to screenpublic void drawNinePatch(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable ninePatchDrawable, float x, float y, float width, float height)
NinePatchDrawable
to screenninePatchDrawable
- The NinePatchDrawable
to be drawnx
- The x coordinate to draw aty
- The y coordiante to draw atwidth
- The width to apply to the NinePatchDrawable
height
- The height to apply to the NinePatchDrawable
public void rotate(float degrees, float x, float y)
degrees
- The degree value in a clockwise directionx
- The x coordinate to rotate aroundy
- The y coordinate to rotate aroundpublic void setRotation(float degrees, float x, float y)
degrees
- The degree value in a clockwise directionx
- The x coordinate to rotate aroundy
- The y coordinate to rotate aroundpublic void scale(float scaleX, float scaleY)
scaleX
- Scaling along the X axisscaleY
- Scaling along the Y axispublic void setScale(float scaleX, float scaleY)
scaleX
- Scaling along the X axisscaleY
- Scaling along the Y axispublic void clearScaling()
public void translate(float translateX, float translateY)
translateX
- The x axis translationtranslateY
- The y axis translationpublic void setTranslation(float translateX, float translateY)
translateX
- The x axis translationtranslateY
- The y axis translationpublic void setClip(float x, float y, float width, float height)
x
- The x coordinate the clip begins aty
- The y coordinate the clip begins atwidth
- The width of the clipheight
- The height of the clippublic void setClip(Rectangle clip)
clip
- The clip areapublic Rectangle removeClip()
public void setTint(com.badlogic.gdx.graphics.Color tint)
Color
to apply to draw operationstint
- The Color
to tint withpublic void setFont(com.badlogic.gdx.graphics.g2d.BitmapFont font)
BitmapFont
to draw String
s withfont
- A non-null instance of BitmapFont
public void removeTint()
Color
public void enableBlending()
public void disableBlending()
public void setShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram shaderProgram)
ShaderProgram
to this instanceshaderProgram
- The ShaderProgram
to applypublic com.badlogic.gdx.graphics.glutils.ShaderProgram getShaderProgram()
ShaderProgram
public void clearShaderProgram()
ShaderProgram
applied to this instancepublic void setBlendFunction(int srcFunc, int dstFunc)
srcFunc
- Source GL functiondstFunc
- Destination GL functionpublic void clearBlendFunction()
public void flush()
public int getLineHeight()
public void setLineHeight(int lineHeight)
lineHeight
- A value greater than 0public com.badlogic.gdx.graphics.Color getColor()
Color
to draw shapes withpublic void setColor(com.badlogic.gdx.graphics.Color color)
Color
to draw shapes withcolor
- public com.badlogic.gdx.graphics.Color getBackgroundColor()
Color
public void setBackgroundColor(com.badlogic.gdx.graphics.Color backgroundColor)
Color
to be usedpublic com.badlogic.gdx.graphics.g2d.BitmapFont getFont()
BitmapFont
to draw String
s withpublic com.badlogic.gdx.graphics.Color getTint()
Color
tint being applied to all draw operationspublic float getScaleX()
public float getScaleY()
public float getTranslationX()
public float getTranslationY()
public float getRotation()
public float getRotationX()
public float getRotationY()
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()
public float getWindowWidth()
public float getWindowHeight()
public float getViewportWidth()
public float getViewportHeight()
public java.lang.String toString()
toString
in class java.lang.Object