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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Dispose()The Dispose action will unload all information that has been loaded using this ImageSheet.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetDrawable(text name)This action will get a Drawable from the ImageSheet.
GetDrawable(text name, integer index)This action will get a Drawable matching the given name and index from the ImageSheet.
GetHashCode()This action gets the hash code for an object.
Load(Libraries.System.File file)This action will load the ImageSheet's data using the given atlas file.
Load(text filePath)This action will load a file as a text file path relative to the project directory.

Actions Documentation

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

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

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

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.

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.

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

Parameters

Return

Libraries.Game.Graphics.Drawable:

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.

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("laser", 2)
                Add(myDrawable)
            end

        end

Parameters

Return

Libraries.Game.Graphics.Drawable:

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.

Load(Libraries.System.File file)

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

Example Code

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

Parameters

Load(text filePath)

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

Example Code

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

Parameters