Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

SpriteHash

SpriteHash is a manager that owns a keyed collection of sprites sharing one
viewport. It handles construction, iteration, bulk updates and disposal, so a
scene can keep all its sprites in a single object.

@sprites = SpriteHash.new(viewport)

@sprites.add(:logo, bitmap: "Graphics/Pictures/logo")
@sprites.add(:bar, type: :Scrolling) do |s|
  s.set_bitmap("loadbar", speed: 2)
end

# every frame:
@sprites.update

# when done:
@sprites.dispose

Adding sprites

  • hash.add(key, options = {}, &block) build and store a sprite under key, yielding it to the block. Recognised options:
    • :type a Sprites::* type symbol (e.g. :Scrolling, :Rainbow, :Sheet)
    • :class an explicit sprite class (overrides :type)
    • :object a pre-built sprite object to adopt
    • :bitmap a path string, or a hash with a :file key plus extra options
  • hash.add_raw(key, object, &block) store a sprite instantiated elsewhere

Access & iteration

  • hash[key] fetch a sprite by key
  • hash.keys all keys · hash.key?(key) whether a key exists
  • hash.each { |key, sprite| } iterate key/sprite pairs
  • hash.each_sprite { |sprite| } iterate sprites
  • hash.each_key { |key| } iterate keys
  • hash.select { |key, sprite| } / hash.reject { |key, sprite| } filter

Bulk operations

  • hash.update update every sprite in the collection
  • hash.set(options = {}) assign an attribute on every sprite (e.g. set(opacity: 0))
  • hash.viewport = vp reassign the viewport across all sprites
  • hash.dispose(options = {}) dispose all sprites; supports :only / :except key filters
  • hash.disposed? whether the collection is empty

Bitmap helpers

Class methods for resolving bitmaps used internally and available directly:

  • SpriteHash.bitmap(path) resolve a bitmap from a path or any bitmap-able object
  • SpriteHash.online_bitmap(url) download and return a bitmap (nil if the downloaded file is unsafe)