Class: Texture2D

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(id, width, height, mipmaps, format) ⇒ Texture2D

Creates a new instance of Texture2D

Parameters:

  • id (Integer)
  • width (Integer)
  • height (Integer)
  • mipmaps (Integer)
  • format (Integer)


9
10
11
12
13
# File 'mrb_doc/models/texture2d.rb', line 9

def initialize(id, width, height, mipmaps, format)
  # mrb_Texture2D_initialize
  # src/mruby_integration/models/texture2d.cpp
  Texture2D.new
end

Instance Attribute Details

#formatInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/texture2d.rb', line 4

def format
  @format
end

#heightInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/texture2d.rb', line 4

def height
  @height
end

#idInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/texture2d.rb', line 4

def id
  @id
end

#mipmapsInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/texture2d.rb', line 4

def mipmaps
  @mipmaps
end

#widthInteger

Returns:

  • (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

Parameters:

  • path (String)

Returns:

Raises:



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.

Parameters:

  • source (Rectangle) (defaults to: nil)
  • destination (Rectangle) (defaults to: nil)
  • origin (Vector2) (defaults to: Vector2::ZERO)
  • rotation (Integer) (defaults to: 0)

    in degrees

  • colour (Colour) (defaults to: WHITE)

Returns:

  • (nil)


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

Parameters:

Returns:

  • (Integer)


62
63
64
# File 'src/ruby/models/texture2d.rb', line 62

def filter=(val)
  set_texture_filter(self, val)
end

#generate_mipmapsInteger

Generates mipmaps for the Texture2D

Returns:

  • (Integer)


68
69
70
# File 'src/ruby/models/texture2d.rb', line 68

def generate_mipmaps
  generate_texture_mipmaps(self)
end

#to_hHash

Return the object represented by a Hash

Returns:

  • (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

#unloadnil

Unloads the texture from memory

Returns:

  • (nil)


29
30
31
# File 'src/ruby/models/texture2d.rb', line 29

def unload
  unload_texture(self)
end