Class: Metro::Image
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Metro::Image
- Defined in:
- lib/metro/image.rb
Overview
Image is a wrapper class for a Gosu Image. This allows for additional data to be stored without relying on monkey-patching on functionality.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
The relative path of the image.
-
#tileable ⇒ Object
readonly
The tileability of the image.
Class Method Summary collapse
-
.create(options) ⇒ Object
Create an image given the window, path, and tileability.
- .crop(window, image, bounds) ⇒ Object
-
.find_or_create(options) ⇒ Object
Finds an existing image or creates a new image given the window, path, and tileablilty.
Instance Method Summary collapse
- #dimensions ⇒ Object
-
#initialize(gosu_image, path, tileable) ⇒ Image
constructor
A new instance of Image.
Constructor Details
#initialize(gosu_image, path, tileable) ⇒ Image
Returns a new instance of Image.
9 10 11 12 13 |
# File 'lib/metro/image.rb', line 9 def initialize(gosu_image,path,tileable) super(gosu_image) @path = path @tileable = tileable end |
Instance Attribute Details
#path ⇒ Object (readonly)
The relative path of the image
16 17 18 |
# File 'lib/metro/image.rb', line 16 def path @path end |
#tileable ⇒ Object (readonly)
The tileability of the image
19 20 21 |
# File 'lib/metro/image.rb', line 19 def tileable @tileable end |
Class Method Details
.create(options) ⇒ Object
Create an image given the window, path, and tileability.
53 54 55 56 57 |
# File 'lib/metro/image.rb', line 53 def self.create() window, asset_path, tileable = create_params() gosu_image = Gosu::Image.new(window,asset_path.filepath,tileable) new gosu_image, asset_path.path, tileable end |
.crop(window, image, bounds) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/metro/image.rb', line 59 def self.crop(window,image,bounds) cropped_image = TexPlay.create_image(window,bounds.width,bounds.height) cropped_image.refresh_cache cropped_image.splice image, 0, 0, crop: [ bounds.left, bounds.top, bounds.right, bounds.bottom ] cropped_image end |
.find_or_create(options) ⇒ Object
Finds an existing image or creates a new image given the window, path, and tileablilty.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/metro/image.rb', line 34 def self.find_or_create() begin File.open(File.join("assets", [:path]), "r") rescue Exception puts $! # <- make this prettier [:path] = "missing.png" # <- make this file installed by default into the assets folder of the game end path = AssetPath.with([:path]) images[path.to_s] or (images[path.to_s] = create()) end |
Instance Method Details
#dimensions ⇒ Object
21 22 23 |
# File 'lib/metro/image.rb', line 21 def dimensions Metro::Units::Dimensions.of width, height end |