Libraries.Game.Graphics.Painter2D Documentation

The Painter2D class is used to draw Drawable objects on the screen. The Game class provides a default Painter2D, which is passed to Items and Drawables via their Draw action. It is highly recommended to use that Painter2D when using the Game class. Note that when using the Game class, in most cases it is not necessary to ever use the Painter2D class manually, as the Game class will automatically draw Drawables that have been added to it.

Example Code

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Drawable square

    action Main
        StartGame()
    end

    action CreateGame
        Color white
        white:SetColor(1, 1, 1, 1)
    
        square:LoadFilledRectangle(200, 200, white)

        myPainter = parent:Game:batch
        Color red
        red:SetColor(1, 0, 0, 1)
        myPainter:SetColor(red)

        Add(square)
    end

end

Inherits from: Libraries.Language.Object

Actions Documentation

Begin()

Activates this Painter2D so it may draw items. If the Painter2D is already active, this will cause an error.

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined

    action Main
        StartGame()
    end

    action CreateGame
        myPainter = parent:Game:batch
        myPainter:Begin()
        myPainter:End()
    end

end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Dispose()

Disposes of the plugin data stored by the Painter2D, freeing up resources when the Painter2D is no longer needed. This should never be called on the default Painter2D provided by the Game class.

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Game

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Painter2D myNewPainter
        myNewPainter:Dispose()
    end

end

Draw(Libraries.Game.Graphics.Drawable drawable)

Immediately draws the given Drawable to the screen on top of any other Drawables which have been drawn this frame, ignoring depth buffer values. This should typically only be used as part of custom drawing in an Item (see Item2D's SetCustomDrawing and Draw actions).

Parameters

End()

Deactivates this Painter2D. A deactivated Painter2D can not draw. If the Painter2D is already deactived, this will cause an error. This action also flushes the Painter's queue, causing any drawing queued up by the Draw action to complete and displaying the new draw buffer.

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined

    action Main
        StartGame()
    end

    action CreateGame
        myPainter = parent:Game:batch
        myPainter:Begin()
        myPainter:End()
    end

end

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

Flush()

This action forces the Painter2D to immediately draw all images it has stored inside of it that are awaiting processing.

GetClipHeight()

The GetClipHeight action returns the height (in world coordinates) of the clipping rectangle.

Return

number: The height of the clipping rectangle.

GetClipWidth()

The GetClipWidth action returns the width (in world coordinates) of the clipping rectangle.

Return

number: The width of the clipping rectangle.

GetClipX()

The GetClipX action returns the x coordinate (in world coordinates) of the bottom-left corner of the clipping rectangle.

Return

number: The bottom-left x coordinate of the clipping rectangle.

GetClipX2()

The GetClipX2 action returns the x coordinate (in world coordinates) of the top-right corner of the clipping rectangle.

Return

number: The top-right x coordinate of the clipping rectangle.

GetClipY()

The GetClipY action returns the y coordinate (in world coordinates) of the bottom-left corner of the clipping rectangle.

Return

number: The bottom-left y coordinate of the clipping rectangle.

GetClipY2()

The GetClipY2 action returns the y coordinate (in world coordinates) of the top-right corner of the clipping rectangle.

Return

number: The top-right y coordinate of the clipping rectangle.

GetColor()

This action returns the current color filter on the Painter2D. The default color filter is white.

Return

Libraries.Game.Graphics.Color:

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Color color

    action Main
        StartGame()
    end

    action CreateGame

        myPainter = parent:Game:batch
        color = myPainter:GetColor()
    end

end

GetDefaultShaderProgram()

The GetClipWidth action returns the width (in world coordinates) of the clipping rectangle.

Return

Libraries.Game.Graphics.Shaders.ShaderProgram: The width of the clipping rectangle.

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

IsBlendingDisabled()

The SetClipCoordinates action sets the x, y coordinates of the bottom-left corner and the x, y coordinates of the top-right corner of the clipping rectangle.

Return

boolean:

IsBlendingEnabled()

This action returns whether the Painter2D is currently set to use blending in OpenGL for the pictures that are being drawn.

Return

boolean:

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Drawable square

    action Main
        StartGame()
    end

    action CreateGame
        myPainter = parent:Game:batch
        output "Is Painter2D blending? " + myPainter:IsBlendingEnabled()
    end

end

IsClipping()

The IsClipping action returns whether or not the Painter is currently using pixel clipping during drawing.

Return

boolean: True to enable clipping, false to disable clipping.

IsCustomDrawing()

This action is used to determine if the Painter is currently custom drawing an Item2D. If it is, this returns true.

Return

boolean: True if the Painter2D is currently custom drawing an Item2D, or false otherwise.

IsDrawing()

This action returns whether the Painter2D is currently active for drawing. A Painter2D becomes active for drawing after calling Painter2D:Begin(), and stays active until Painter2D:End() is called.

Return

boolean:

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Drawable square

    action Main
        StartGame()
    end

    action CreateGame
        myPainter = parent:Game:batch
        myPainter:Begin()
        output "Is Painter2D drawing? " + myPainter:IsDrawing()
        myPainter:End()
    end

end

QueueForDrawing(Libraries.Game.Graphics.Drawable drawable)

Draws a Drawable on the screen. A Painter2D must be activated with Begin() before it can draw. When using this in the game engine, this should be used inside the Draw action of a class inheriting from Item. If it is drawn as part of the normal update process, the image will draw, then immediately be covered over by the Game's drawing step, keeping the drawn object from being seen.

Parameters

QueueForDrawing(Libraries.Interface.Item2D item)

This action queues an Item2D for rendering. Because Item2Ds (other than Drawables) cannot normally be rendered, this will have no effect unless the Item2D is either a Drawable or the Item2D has custom drawing enabled.

Parameters

SetCamera(Libraries.Game.Graphics.Camera camera)

This action will set the Painter2D to render objects on the screen relative to the given camera.

Parameters

SetClipCoordinates(number x1, number y1, number x2, number y2)

The SetClipCoordinates action sets the x, y coordinates of the bottom-left corner and the x, y coordinates of the top-right corner of the clipping rectangle.

Parameters

  • number x1: The x coordinate of the left side of the rectangle.
  • number y1: The y coordinate of the bottom side of the rectangle.
  • number x2: The x coordinate of the right side of the rectangle.
  • number y2: The y coordinate of the top side of the rectangle.

SetClipDimensions(number x, number y, number width, number height)

The SetClipDimensions action sets the x, y coordinates of the bottom-left corner and the width and height of the clipping rectangle.

Parameters

  • number x: The x coordinate of the left side of the rectangle.
  • number y: The y coordinate of the bottom side of the rectangle.
  • number width: The width of the rectangle.
  • number height: The height of the rectangle.

SetClipping(boolean clip)

The SetClipping action enables pixel clipping for anything which is drawn by this Painter. Pixels are clipped in a rectangle defined by the Painter's clip coordinates.

Parameters

  • boolean clip: True to enable clipping, false to disable clipping.

SetColor(Libraries.Game.Graphics.Color newColor)

This action will set a color filter on the painter, causing all Drawables drawn by this painter to be tinted with the given color.

Parameters

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Drawable square

    action Main
        StartGame()
    end

    action CreateGame
        Color white
        white:SetColor(1, 1, 1, 1)

        square:LoadFilledRectangle(200, 200, white)

        myPainter = parent:Game:batch
        Color red
        red:SetColor(1, 0, 0, 1)
        myPainter:SetColor(red)

        Add(square)
    end

end

SetColor(number red, number green, number blue, number alpha)

This action will set a color filter on the painter, causing all Drawables drawn by this painter to be tinted with the given color. The color is set by using four component values between 0 and 1, which represent red, green, blue, and alpha, in that order.

Parameters

  • number red
  • number green
  • number blue
  • number alpha

Example

use Libraries.Game.Graphics.Painter2D
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Painter2D myPainter = undefined
    Drawable square

    action Main
        StartGame()
    end

    action CreateGame
        Color white
        white:SetColor(1, 1, 1, 1)

        square:LoadFilledRectangle(200, 200, white)

        myPainter = parent:Game:batch
        myPainter:SetColor(1, 0, 0, 1)

        Add(square)
    end

end

SetDefaultShaderProgram(Libraries.Game.Graphics.Shaders.ShaderProgram program)

The GetClipHeight action returns the height (in world coordinates) of the clipping rectangle.

Parameters