Class: Texture2D
- Inherits:
-
Object
- Object
- Texture2D
- Defined in:
- src/ruby/models/texture2d.rb,
mrb_doc/models/texture2d.rb
Overview
The Texture2D class is most often used for drawing sprites.
Defined Under Namespace
Classes: NotFound
Instance Attribute Summary collapse
Class Method Summary collapse
-
.load(path) ⇒ Texture2D
Loads a texture from the specified path.
Instance Method Summary collapse
-
#draw(source: nil, destination: nil, origin: Vector2::ZERO, rotation: 0, colour: WHITE) ⇒ nil
Draws the texture segment defined by source at the given destination, rotated around the origin in the specified colour.
-
#filter=(val) ⇒ Integer
Sets the filtering for the Texture2D.
-
#generate_mipmaps ⇒ Integer
Generates mipmaps for the Texture2D.
-
#initialize(id, width, height, mipmaps, format) ⇒ Texture2D
constructor
Creates a new instance of Texture2D.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
-
#unload ⇒ nil
Unloads the texture from memory.
Constructor Details
Instance Attribute Details
#format ⇒ Integer
4 5 6 |
# File 'src/ruby/models/texture2d.rb', line 4 def format @format end |
#height ⇒ Integer
4 5 6 |
# File 'src/ruby/models/texture2d.rb', line 4 def height @height end |
#id ⇒ Integer
4 5 6 |
# File 'src/ruby/models/texture2d.rb', line 4 def id @id end |
#mipmaps ⇒ Integer
4 5 6 |
# File 'src/ruby/models/texture2d.rb', line 4 def mipmaps @mipmaps end |
#width ⇒ Integer
4 5 6 |
# File 'src/ruby/models/texture2d.rb', line 4 def width @width end |
Class Method Details
.load(path) ⇒ Texture2D
Loads a texture from the specified path
22 23 24 25 |
# File 'src/ruby/models/texture2d.rb', line 22 def self.load(path) raise Texture2D::NotFound.new("Could not find file at path \"#{path}\"") unless File.exist?(path) load_texture(path) end |
Instance Method Details
#draw(source: nil, destination: nil, origin: Vector2::ZERO, rotation: 0, colour: WHITE) ⇒ nil
Draws the texture segment defined by source at the given destination, rotated around the origin in the specified colour. If source is not defined it defaults to the full image. If destination is not defined it defaults to source.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'src/ruby/models/texture2d.rb', line 43 def draw(source: nil, destination: nil, origin: Vector2::ZERO, rotation: 0, colour: WHITE) @source = source unless source.nil? @source ||= Rectangle.new(0, 0, self.width, self.height) @destination = destination unless destination.nil? @destination ||= @source draw_texture_pro( self, @source, @destination, origin, rotation, colour ) end |
#filter=(val) ⇒ Integer
Sets the filtering for the Texture2D
62 63 64 |
# File 'src/ruby/models/texture2d.rb', line 62 def filter=(val) set_texture_filter(self, val) end |
#generate_mipmaps ⇒ Integer
Generates mipmaps for the Texture2D
68 69 70 |
# File 'src/ruby/models/texture2d.rb', line 68 def generate_mipmaps generate_texture_mipmaps(self) end |
#to_h ⇒ Hash
Return the object represented by a Hash
8 9 10 11 12 13 14 15 16 |
# File 'src/ruby/models/texture2d.rb', line 8 def to_h { id: id, width: width, height: height, mipmaps: mipmaps, format: format, } end |
#unload ⇒ nil
Unloads the texture from memory
29 30 31 |
# File 'src/ruby/models/texture2d.rb', line 29 def unload unload_texture(self) end |