Package com.csse3200.game.rendering
Class ColorDrawable
java.lang.Object
com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable
com.csse3200.game.rendering.ColorDrawable
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Drawable,IAlpha
public class ColorDrawable
extends com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable
implements IAlpha
This class is used to programmatically create a color which can be used as a background in UI components.
Taken from a StackOverflow answer by Steve Moseley.
-
Constructor Summary
ConstructorsConstructorDescriptionColorDrawable(float red, float green, float blue, float alpha) Creates a new ColorDrawable with the given color (in RGB). -
Method Summary
Methods inherited from class com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable
getBottomHeight, getLeftWidth, getMinHeight, getMinWidth, getName, getRightWidth, getTopHeight, setBottomHeight, setLeftWidth, setMinHeight, setMinSize, setMinWidth, setName, setPadding, setRightWidth, setTopHeight, toString
-
Constructor Details
-
ColorDrawable
public ColorDrawable(float red, float green, float blue, float alpha) Creates a new ColorDrawable with the given color (in RGB).- Parameters:
red- - the fraction of red in the color (0 to 1)green- - the fraction of green in the color (0 to 1)blue- - the fraction of blue in the color (0 to 1)alpha- - the fraction of alpha in the color (0 to 1)
-
-
Method Details
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y, float width, float height) Draws the ColorDrawable to the screen by recoloring a white texture to the defined color.- Specified by:
drawin interfacecom.badlogic.gdx.scenes.scene2d.utils.Drawable- Overrides:
drawin classcom.badlogic.gdx.scenes.scene2d.utils.BaseDrawable- Parameters:
batch- - the batch to draw the color to.x- - the x position of the drawabley- - the y position of the drawablewidth- - the width of the drawableheight- - the height of the drawable
-
setAlpha
public void setAlpha(float alpha) Changes the alpha of the ColorDrawable.
-