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

    e

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
ApplyCamera(Libraries.Game.Graphics.Camera camera)This action will set the Painter2D to render objects on the screen relative to the given camer
Begin()Activates this Painter2D so it may draw items.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Dispose()Disposes of the plugin data stored by the Painter2D, freeing up resources when the Painter2D is no longer needed.
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.
End()Deactivates this Painter2D.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Flush()This action forces the Painter2D to immediately draw all images it has stored inside of it that are awaiting processin
GetClipHeight()The GetClipHeight action returns the height (in world coordinates) of the clipping rectangle.
GetClipWidth()The GetClipWidth action returns the width (in world coordinates) of the clipping rectangle.
GetClipX()The GetClipX action returns the x coordinate (in world coordinates) of the bottom-left corner of the clipping rectangle.
GetClipX2()The GetClipX2 action returns the x coordinate (in world coordinates) of the top-right corner of the clipping rectangle.
GetClipY()The GetClipY action returns the y coordinate (in world coordinates) of the bottom-left corner of the clipping rectangle.
GetClipY2()The GetClipY2 action returns the y coordinate (in world coordinates) of the top-right corner of the clipping rectangle.
GetColor()This action returns the current color filter on the Painter2D.
GetHashCode()This action gets the hash code for an object.
IsBlendingEnabled()This action returns whether the Painter2D is currently set to use blending in OpenGL for the pictures that are being drawn.
IsClipping()The IsClipping action returns whether or not the Painter is currently using pixel clipping during drawing.
IsCustomDrawing()This action is used to determine if the Painter is currently custom drawing an Item2D.
IsDrawing()This action returns whether the Painter2D is currently active for drawing.
QueueForDrawing(Libraries.Game.Graphics.Drawable drawable)Draws a Drawable on the screen.
QueueForDrawing(Libraries.Interface.Item2D item)
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.
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.
SetClipping(boolean clip)The SetClipping action enables pixel clipping for anything which is drawn by this Painter.
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.
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.

Actions Documentation

ApplyCamera(Libraries.Game.Graphics.Camera camera)

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

Parameters

Begin()

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

Example Code

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

        e

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.

Example Code

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

Parameters

Return

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

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 Code

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

        class Main is Game

            action Main
                StartGame()
            end

            action CreateGame
                Painter2D myNewPainter
                myNewPainter:Dispose()
            end

        e

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 Code

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

        e

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

Flush()

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

GetClipHeight()

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

Return

number: The height of the clipping rectangl

GetClipWidth()

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

Return

number: The width of the clipping rectangl

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 rectangl

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 rectangl

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 rectangl

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 rectangl

GetColor()

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

Example Code

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

        e

Return

Libraries.Game.Graphics.Color:

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode

Return

integer: The integer hash code of the object.

IsBlendingEnabled()

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

Example Code

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

        e

Return

boolean:

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 clippin

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 otherwis

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.

Example Code

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

        e

Return

boolean:

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 see

Parameters

QueueForDrawing(Libraries.Interface.Item2D item)

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

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

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

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.

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

        e

Parameters

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.

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
                myPainter:SetColor(1, 0, 0, 1)

                Add(square)
            end

        e

Parameters