Class: Ruby2D::PixmapAtlas
- Inherits:
-
Object
- Object
- Ruby2D::PixmapAtlas
- Defined in:
- lib/ruby2d/pixmap_atlas.rb
Overview
A pixmap is a 2D grid of pixel data of fixed width and height. A pixmap atlas is a dictionary of named pixmaps where each named pixmap is loaded once and can be re-used multiple times without the overhead of repeated loading and multiple copies.
Instance Method Summary collapse
-
#[](name) ⇒ Pixmap?
Find a previosly loaded Pixmap in the atlas by name.
-
#clear ⇒ Object
Empty the atlas, eventually releasing all the loaded pixmaps (except for any that are referenced elsewhere).
-
#count ⇒ Object
Get the number of Pixmaps in the atlas.
-
#each(&block) ⇒ Object
Iterate through each Pixmap in the atlas.
-
#initialize ⇒ PixmapAtlas
constructor
A new instance of PixmapAtlas.
-
#load_and_keep_image(file_path, as: nil) ⇒ Pixmap
Load a pixmap from an image
file_path
and store itas
named for later lookup.
Constructor Details
#initialize ⇒ PixmapAtlas
Returns a new instance of PixmapAtlas.
11 12 13 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 11 def initialize @atlas = {} # empty map end |
Instance Method Details
#[](name) ⇒ Pixmap?
Find a previosly loaded Pixmap in the atlas by name
25 26 27 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 25 def [](name) @atlas[name] end |
#clear ⇒ Object
Empty the atlas, eventually releasing all the loaded pixmaps (except for any that are referenced elsewhere)
17 18 19 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 17 def clear @atlas.clear end |
#count ⇒ Object
Get the number of Pixmaps in the atlas
30 31 32 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 30 def count @atlas.count end |
#each(&block) ⇒ Object
Iterate through each Pixmap in the atlas
35 36 37 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 35 def each(&block) @atlas.each(&block) end |
#load_and_keep_image(file_path, as: nil) ⇒ Pixmap
Load a pixmap from an image file_path
and store it as
named for later lookup.
46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby2d/pixmap_atlas.rb', line 46 def load_and_keep_image(file_path, as: nil) name = as || file_path if @atlas.member? name @atlas[name] else pixmap = Pixmap.new file_path @atlas[name] = pixmap end end |