Module: OR2D::Resource
Overview
The Resource module contains helper methods for creating resources.
Instance Method Summary collapse
-
#create(type, options) ⇒ Object
Construct a new resource of the given type with the passed options.
-
#create_circle(options) ⇒ Ruby2D::Circle
Create a Ruby2D::Circle object from the given options.
-
#create_image(options) ⇒ Ruby2D::Image
Create a Ruby2D::Image object from the given options.
-
#create_line(options) ⇒ Ruby2D::Line
Create a Ruby2D::Line object from the given options.
-
#create_quad(options) ⇒ Ruby2D::Quad
Create a Ruby2D::Quad object from the given options.
-
#create_rectangle(options) ⇒ Ruby2D::Rectangle
Create a Ruby2D::Rectangle object from the given options.
-
#create_sprite(options) ⇒ Ruby2D::Sprite
Create a Ruby2D::Sprite object from the given options.
-
#create_square(options) ⇒ Ruby2D::Square
Create a Ruby2D::Square object from the given options.
-
#create_text(options) ⇒ Ruby2D::Text
Create a Ruby2D::Text object from the given options.
-
#create_tileset(options) ⇒ Ruby2D::Tileset
Create a Ruby2D::Tileset object from the given options.
-
#create_triangle(options) ⇒ Ruby2D::Triangle
Create a Ruby2D::Triangle object from the given options.
Instance Method Details
#create(type, options) ⇒ Object
Construct a new resource of the given type with the passed options.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/or2d/resource.rb', line 9 def create(type, ) case type when :image then OR2D::Resource.create_image() when :sprite then OR2D::Resource.create_sprite() when :text then OR2D::Resource.create_text() when :tileset then OR2D::Resource.create_tileset() when :triangle then OR2D::Resource.create_triangle() when :quad then OR2D::Resource.create_quad() when :circle then OR2D::Resource.create_circle() when :square then OR2D::Resource.create_square() when :line then OR2D::Resource.create_line() when :rectangle then OR2D::Resource.create_rectangle() else raise "Unknown resource type: #{type}!" end end |
#create_circle(options) ⇒ Ruby2D::Circle
Create a Ruby2D::Circle object from the given options.
28 29 30 31 32 33 34 35 36 |
# File 'lib/or2d/resource.rb', line 28 def create_circle() Ruby2D::Circle.new(x: [:x] || 0, y: [:y] || 0, z: [:z] || 0, radius: [:radius] || 50, sectors: [:sectors] || 30, color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |
#create_image(options) ⇒ Ruby2D::Image
Create a Ruby2D::Image object from the given options.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/or2d/resource.rb', line 41 def create_image() Ruby2D::Image.new([:path], atlas: [:atlas], width: [:width] * OR2D.scale || 4, height: [:height] * OR2D.scale || 4, opacity: [:opacity] || 1.0, rotate: [:rotate] || 0, x: [:x] || 0, y: [:y] || 0, z: [:z] || 0) end |
#create_line(options) ⇒ Ruby2D::Line
Create a Ruby2D::Line object from the given options.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/or2d/resource.rb', line 56 def create_line() Ruby2D::Line.new(x1: [:x1], y1: [:y1], x2: [:x2], y2: [:y2], z: [:z], width: [:width] * OR2D.scale || 2, color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |
#create_quad(options) ⇒ Ruby2D::Quad
Create a Ruby2D::Quad object from the given options.
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/or2d/resource.rb', line 165 def create_quad() Ruby2D::Quad.new(x1: [:x1], y1: [:y1], x2: [:x2], y2: [:y2], x3: [:x3], y3: [:y3], x4: [:x4], y4: [:y4], z: [:z], color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |
#create_rectangle(options) ⇒ Ruby2D::Rectangle
Create a Ruby2D::Rectangle object from the given options.
70 71 72 73 74 75 76 77 78 |
# File 'lib/or2d/resource.rb', line 70 def create_rectangle() Ruby2D::Rectangle.new(x: [:x] || 0, y: [:y] || 0, z: [:z] || 0, width: [:width] * OR2D.scale, height: [:height] * OR2D.scale, color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |
#create_sprite(options) ⇒ Ruby2D::Sprite
Create a Ruby2D::Sprite object from the given options.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/or2d/resource.rb', line 83 def create_sprite() Ruby2D::Sprite.new([:path], atlas: [:atlas], width: [:width] ? [:width] * OR2D.scale : nil, height: [:height] ? [:height] * OR2D.scale : nil, rotate: [:rotate] || 0, opacity: [:opacity] || 1.0, loop: [:loop] || false, time: [:time] || 100, animations: [:animations] || {}, default: [:default] || 0, clip_height: [:clip_height], clip_width: [:clip_width], clip_x: [:clip_x] || 0, clip_y: [:clip_y] || 0, x: [:x] || 0, y: [:y] || 0, z: [:z] || 0) end |
#create_square(options) ⇒ Ruby2D::Square
Create a Ruby2D::Square object from the given options.
106 107 108 109 110 111 112 113 |
# File 'lib/or2d/resource.rb', line 106 def create_square() Ruby2D::Square.new(x: [:x] || 0, y: [:y] || 0, z: [:z] || 0, size: [:size], color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |
#create_text(options) ⇒ Ruby2D::Text
Create a Ruby2D::Text object from the given options.
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/or2d/resource.rb', line 118 def create_text() Ruby2D::Text.new([:text], x: [:x] || 0, y: [:y] || 0, z: [:z] || 0, size: ([:size] || 16) * OR2D.scale, style: [:style], font: [:font] || Ruby2D::Font.default, color: [:color] || 'yellow', rotate: [:rotate] || 0, opacity: [:opacity] || 1.0) end |
#create_tileset(options) ⇒ Ruby2D::Tileset
Create a Ruby2D::Tileset object from the given options.
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/or2d/resource.rb', line 134 def create_tileset() Ruby2D::Tileset.new([:path], tile_width: [:tile_width] || 16, tile_height: [:tile_height] || 16, width: [:width], height: [:height], z: [:z] || 100, padding: [:padding] || 0, spacing: [:spacing] || 0, scale: [:scale] || 1, show: [:show] || false) end |
#create_triangle(options) ⇒ Ruby2D::Triangle
Create a Ruby2D::Triangle object from the given options.
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/or2d/resource.rb', line 150 def create_triangle() Ruby2D::Triangle.new(x1: [:x1], y1: [:y1], x2: [:x2], y2: [:y2], x3: [:x3], y3: [:y3], z: [:z], color: [:color] || 'yellow', opacity: [:opacity] || 1.0) end |