Libraries.Game.Graphics.Texture Documentation

The Texture class represents an image that can be drawn on the screen. Once an image is loaded into a texture, it can be drawn on the screen by loading it into a Drawable.

Example Code

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game

    Drawable drawable
    Texture texture
    Color red

    action Main
        StartGame()
    end

    action CreateGame
        red:SetColor(1, 0, 0, 1)
        texture:LoadFilledRectangle(80, 100, red)
        drawable:Load(texture)

        drawable:SetPosition(200, 200)
        Add(drawable)
    end
end

Inherits from: Libraries.Language.Object, Libraries.Game.Disposable

Actions Documentation

AddTextureLoadListener(Libraries.Interface.Events.TextureLoadListener listener)

This action adds a TextureLoadListener to the texture. If the texture finishes asynchronously loading an image, the listener will be alerted.

Parameters

Bind()

This action activates this texture and binds the texture image to the internal texture ID. This is for internal use.

Bind(integer textureUnit)

This action binds the texture image to an internal index in the rendering system. This is used internally by the engine as needed, and most users won't need to use it directly.

Parameters

  • integer textureUnit

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

This action will release the memory used to store pixel information for this Texture. This frees up resources, but will make the Texture no longer usable, including in classes that may have loaded the Texture, such as in Drawable. Use this when you are completely finished with a Texture and no longer intend to use it.

EmptyTextureLoadListeners()

This action removes all TextureLoadListeners that have been added to the texture.

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)

FinishLoadingAsynchronously(Libraries.System.File file, Libraries.Game.Graphics.PixelMap pixelMap, Libraries.Game.Graphics.Format format, boolean useMipMaps, Libraries.Game.Graphics.Drawable drawable)

This action is used internally by the game engine to finish loading the data loaded by a LoadAsynchronously action. After this Texture has finished loading, the provided Drawable will be loaded with this Texture (if it is not undefined). This action is used by the engine automatically as needed, and most users will never need to use this action directly.

Parameters

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

GetHeight()

This action returns the height of a loaded Texture.

Return

integer:

Example

use Libraries.Game.Texture
use Libraries.Game.Game

class Main is Game

    Texture myTexture

    action Main
        StartGame()
    end

    action CreateGame
        // This call will load an image "Sample.png" from a directory called "Images".
        myTexture:LoadFromFile("Images/Sample.png")
        number width = myTexture:GetHeight()
    end
end

GetHorizontalWrap()

This action returns the horizontal texture wrapping mode. For more on how the TextureWrap works, see Libraries.Game.Graphics.TextureWrap.

Return

Libraries.Game.Graphics.TextureWrap:

GetMagnifyFilter()

This action returns the magnification filter of this Texture. For more on how the TextureFilters work, see Libraries.Game.Graphics.TextureFilter.

Return

Libraries.Game.Graphics.TextureFilter:

GetMinimizeFilter()

This action returns the minimization filter of this Texture. For more on how the TextureFilters work, see Libraries.Game.Graphics.TextureFilter.

Return

Libraries.Game.Graphics.TextureFilter:

GetSource()

This action returns the relative file path to the file that was used to load this texture, if there is one. If no file has been loaded, this will return an empty string instead.

Return

text: The relative file path to the loaded file, or the empty string if no file is loaded.

GetVerticalWrap()

This action returns the vertical texture wrapping mode. For more on how the TextureWrap works, see Libraries.Game.Graphics.TextureWrap.

Return

Libraries.Game.Graphics.TextureWrap:

GetWidth()

This action returns the width of a loaded Texture.

Return

integer:

Example

use Libraries.Game.Texture
use Libraries.Game.Game

class Main is Game

    Texture myTexture

    action Main
        StartGame()
    end

    action CreateGame
        // This call will load an image "Sample.png" from a directory called "Images".
        myTexture:LoadFromFile("Images/Sample.png")
        number width = myTexture:GetWidth()
    end
end

IsLoadingAsynchronously()

This action returns true if the texture is asynchronously loading. While loading, the texture won't be ready for use yet. Once the texture has loaded, any registered TextureLoadListeners will be triggered.

Return

boolean: True if this texture is currently loading a file, or false otherwise.

LoadAsynchronously(Libraries.System.File file, Libraries.Game.Graphics.Format format, boolean useMipMaps, Libraries.Game.Graphics.Drawable drawable)

This action will load a texture asynchronously (that is, the texture is loaded separately from the rest of the program's execution) and then load that texture into the provided Drawable. This action is called internally and automatically by the game engine when run on the web. Most users will never need to use this action directly.

Parameters

LoadAsynchronously(text filePath, Libraries.Game.Graphics.Drawable drawable)

This action will load a texture asynchronously (that is, the texture is loaded separately from the rest of the program's execution) and then load that texture into the provided Drawable. This action is called internally and automatically by the game engine when run on the web. Most users will never need to use this action directly.

Parameters

  • text filePath: A file path pointing to the image file to load into this Texture.
  • Libraries.Game.Graphics.Drawable: A drawable that will be loaded with this Texture after the Texture has finished loading.

LoadAsynchronously(Libraries.System.File file, Libraries.Game.Graphics.Drawable drawable)

This action will load a texture asynchronously (that is, the texture is loaded separately from the rest of the program's execution) and then load that texture into the provided Drawable. This action is called internally and automatically by the game engine when run on the web. Most users will never need to use this action directly.

Parameters

LoadCircle(integer radius, Libraries.Game.Graphics.Color color)

This action will create a new Texture with a hollow circle of the given color with the given radius.

Parameters

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Color red
        red:SetColor(1, 0, 0, 1)
        Texture texture
        texture:LoadCircle(75, red)
        Drawable circle
        circle:Load(texture)
        circle:SetPosition(50, 50)
        Add(circle)
    end
end

LoadCircle(integer radius)

This action will create a new Texture with a hollow white circle with the given radius.

Parameters

  • integer radius

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Texture texture
        texture:LoadCircle(75)
        circle:Load(texture)
        circle:SetPosition(50, 50)
        Add(circle)
    end
end

LoadFilledCircle(integer radius, Libraries.Game.Graphics.Color color)

This action will create a new Texture with a solid circle of the given color with the given radius.

Parameters

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Color blue
        blue:SetColor(0, 0, 1, 1)
        Texture texture
        texture:LoadCircle(75, blue)
        Drawable circle
        circle:Load(texture)
        circle:SetPosition(50, 50)
        Add(circle)
    end
end

LoadFilledCircle(integer radius)

This action will create a new Texture with a solid white circle with the given radius.

Parameters

  • integer radius

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Texture texture
        texture:LoadFilledCircle(75)
        Drawable circle
        circle:Load(texture)
        circle:SetPosition(50, 50)
        Add(circle)
    end
end

LoadFilledRectangle(integer width, integer height)

This action will create a new Texture with a solid white rectangle with the given width and height.

Parameters

  • integer width
  • integer height

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Texture texture
        texture:LoadFilledRectangle(20, 100)
        Drawable rectangle
        rectangle:Load(texture)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

LoadFilledRectangle(integer width, integer height, Libraries.Game.Graphics.Color color)

This action will create a new Texture with a solid rectangle of the given color with the given width and height.

Parameters

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Color green
        green:SetColor(0, 1, 0, 1)
        Texture texture
        texture:LoadFilledRectangle(20, 100, green)
        Drawable rectangle
        rectangle:Load(texture)
        rectangle:SetPosition(50, 50)
        Add(rectangle)
    end
end

LoadFilledTriangle(integer x1, integer y1, integer x2, integer y2, integer x3, integer y3)

This action will create a new Texture with a solid white triangle that is made of the points identified by the three given points.

Parameters

  • integer x1
  • integer y1
  • integer x2
  • integer y2
  • integer x3
  • integer y3

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Texture texture
        texture:LoadFilledTriangle(0, 0, 200, 200, 400, 0)
        Drawable triangle
        triangle:Load(texture)
        triangle:SetPosition(50, 50)
        Add(triangle)
    end
end

LoadFilledTriangle(integer x1, integer y1, integer x2, integer y2, integer x3, integer y3, Libraries.Game.Graphics.Color color)

This action will create a new Texture with a solid triangle of the given color that is made of the points identified by the three given points.

Parameters

Example

use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Game.Game

class Main is Game
    
    action Main
        StartGame()
    end

    action CreateGame
        Color purple
        purple:SetColor(0.5, 0, 0.5, 1)
        Texture texture
        texture:LoadFilledTriangle(0, 0, 200, 200, 400, 0, purple)
        Drawable triangle
        triangle:Load(texture)
        triangle:SetPosition(50, 50)
        Add(triangle)
    end
end

LoadFromFile(Libraries.System.File file)

This action loads a Texture from a Quorum File. The File must already have its path set for this function.

Parameters

Example

use Libraries.Game.Texture
use Libraries.Game.Game
use Libraries.System.File

class Main is Game

    File myFile
    Texture myTexture

    action Main
        StartGame()
    end

    action CreateGame
        myFile:SetPath("Images/Sample.png")

        // This call will load the image that the "myFile" variable points to.
        // The file points to an image called "Sample.png" in a folder called "Images".
        myTexture:LoadFromFile(myFile)
    end
end

LoadFromFile(text filePath)

This action loads a Texture from a file path given as text. The file path should be given relative to the directory where the program is executed from.

Parameters

  • text filePath: A file path pointing to the image file to load into this Texture.

Example

use Libraries.Game.Texture
use Libraries.Game.Game

class Main is Game

    Texture myTexture

    action Main
        StartGame()
    end

    action CreateGame
        // This call will load an image "Sample.png" from a directory called "Images".
        myTexture:LoadFromFile("Images/Sample.png")
    end
end

LoadFromMatrix(Libraries.Compute.Matrix matrix)

This action will load a matrix into the Texture to create a monochrome (black and white) image. Each value is assumed to be between 0 and 1, where 0 represents a black pixel and 1 represents a white pixel.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Texture
use Libraries.Compute.Matrix

class Main is Game

    Texture texture
    Drawable drawable

    action Main
        StartGame()
    end

    action CreateGame
        Matrix matrix

        // 7x7 square that is black at edges and lightens as it goes towards the center.
        matrix:Fill(7, 7, 0)
        matrix:Set(1, 1, 0.33)
        matrix:Set(2, 1, 0.33)
        matrix:Set(3, 1, 0.33)
        matrix:Set(4, 1, 0.33)
        matrix:Set(5, 1, 0.33)
        matrix:Set(5, 2, 0.33)
        matrix:Set(5, 3, 0.33)
        matrix:Set(5, 4, 0.33)
        matrix:Set(5, 5, 0.33)
        matrix:Set(4, 5, 0.33)
        matrix:Set(3, 5, 0.33)
        matrix:Set(2, 5, 0.33)
        matrix:Set(1, 5, 0.33)
        matrix:Set(1, 4, 0.33)
        matrix:Set(1, 3, 0.33)
        matrix:Set(1, 2, 0.33)

        matrix:Set(2, 2, 0.66)
        matrix:Set(3, 2, 0.66)
        matrix:Set(4, 2, 0.66)
        matrix:Set(4, 3, 0.66)
        matrix:Set(4, 4, 0.66)
        matrix:Set(3, 4, 0.66)
        matrix:Set(2, 4, 0.66)
        matrix:Set(2, 3, 0.66)

        matrix:Set(3, 3, 1)

        // Loading the Texture and blowing up the size of the Drawable to make it easier to see.
        texture:LoadFromMatrix(matrix)
        drawable:Load(texture)
        Add(drawable)

        drawable:SetPosition(200, 200)
        drawable:SetSize(100, 100)
    end
end

LoadFromPixelMap(Libraries.Game.Graphics.PixelMap pixelMap, Libraries.Game.Graphics.Format format, boolean useMipMaps)

The LoadFromPixelMap action loads a PixelMap into this texture, using the given Format. If mip-mapping is supported on the given platform, mip-maps will be used if the boolean parameter is true.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.PixelMap
use Libraries.Game.Graphics.Format
use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color

class Main is Game

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        PixelMap map
        Format format
        format:SetValue(format:RGBA8888)
        map:CreatePixelMap(200, 200, format)

        // We will create a pink box with a red stripe across it.
        map:Fill(color:Pink())

        integer x = 0
        integer y = 85
        repeat while y < 125
            x = 0
            repeat while x < 200
                map:SetPixel(x, y, color:Red())
                x = x + 1
            end
            y = y + 1
        end

        Texture texture
        texture:LoadFromPixelMap(map, format, false)

        Drawable drawable
        drawable:Load(texture)
        Add(drawable)
    end
end

LoadFromPixelMap(Libraries.Game.Graphics.PixelMap pixelMap)

The LoadFromPixelMap action loads a PixelMap into this texture. The PixelMap will use its already given Format.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.PixelMap
use Libraries.Game.Graphics.Format
use Libraries.Game.Graphics.Texture
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color

class Main is Game

    Color color

    action Main
        StartGame()
    end

    action CreateGame
        PixelMap map
        Format format
        format:SetValue(format:RGBA8888)
        map:CreatePixelMap(200, 200, format)

        // We will create a pink box with a red stripe across it.
        map:Fill(color:Pink())

        integ