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

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 camera.
Begin()Activates this Painter2D so it may draw items.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
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)Draws a Drawable on the screen.
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 processing.
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.
IsDrawing()This action returns whether the Painter2D is currently active for drawing.
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 camera.

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

        end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: 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

        end

Draw(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

End()

Deactivates this Painter2D. A deactivated Painter2D can not draw. If the Painter2D is already deactived, 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

        end

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(t)

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 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.

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

        end

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

        end

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 clipping.

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

        end

Return

boolean:

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

        end

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

        end

Parameters