Libraries.Game.Graphics.ImageSheet Documentation

The ImageSheet class is used to handle many images spread across different files. It loads a .atlas file, and then can be used to get Libraries.Game.Graphics.Drawable objects from the files.

Example Code

use Libraries.Game.Graphics.ImageSheet
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet
    Drawable myDrawable

    action Main
        StartGame()
    end

    action CreateGame
        sheet:Load("MySheet.atlas")
        myDrawable = sheet:GetDrawable("Spaceship")
        Add(myDrawable)
    end

end

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

Actions Documentation

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

The Dispose action will unload all information that has been loaded using this ImageSheet. Any items that are currently using a texture retrieved from this ImageSheet will no longer be able to use them, so this should only be done if the textures from the ImageSheet are not being used.

Example

use Libraries.Game.Graphics.ImageSheet
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet
    Drawable myDrawable

    action Main
        StartGame()
    end

    action CreateGame
        sheet:Load("MySheet.atlas")
        myDrawable = sheet:GetDrawable("Spaceship")
        Add(myDrawable)

        // When we are no longer using any Drawables made from the
        // ImageSheet, we can remove them from the Game, and then 
        // Dispose the ImageSheet to clean up the memory it used.
        Remove(myDrawable)
        sheet:Dispose()
    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)

GetDrawable(text name)

This action will get a Drawable from the ImageSheet. If the ImageSheet hasn't been loaded yet, this will throw an error.

Parameters

  • text name

Return

Libraries.Game.Graphics.Drawable:

Example

use Libraries.Game.Graphics.ImageSheet
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet
    Drawable myDrawable

    action Main
        StartGame()
    end

    action CreateGame
        sheet:Load("MySheet.atlas")
        myDrawable = sheet:GetDrawable("Spaceship")
        Add(myDrawable)
    end

end

GetDrawable(text name, integer index)

This action will get a Drawable matching the given name and index from the ImageSheet. This is used in the case where you have files that end with an underscore followed by a number, e.g. "laser_1.png" and "laser_2.png". The text name should be the name before the underscore. If the ImageSheet hasn't been loaded yet, this will throw an error.

Parameters

  • text name
  • integer index

Return

Libraries.Game.Graphics.Drawable:

Example

use Libraries.Game.Graphics.ImageSheet
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet
    Drawable myDrawable

    action Main
        StartGame()
    end

    action CreateGame
        sheet:Load("MySheet.atlas")
        myDrawable = sheet:GetDrawable("laser", 2)
        Add(myDrawable)
    end

end

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

Load(Libraries.System.File file)

This action will load the ImageSheet's data using the given atlas file.

Parameters

Example

use Libraries.Game.Graphics.ImageSheet
use Libraries.System.File
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet

    action Main
        StartGame()
    end

    action CreateGame
        File sheetFile
        sheetFile:SetPath("Run/Assets/Images.atlas")
        sheet:Load(sheetFile)
    end

end

Load(text filePath)

This action will load a file as a text file path relative to the project directory.

Parameters

  • text filePath

Example

use Libraries.Game.Graphics.ImageSheet
use Libraries.Game.Game

class Main is Game

    ImageSheet sheet

    action Main
        StartGame()
    end

    action CreateGame
        sheet:Load("Run/Assets/Images.atlas")
    end

end