Class: Chingu::Text
- Inherits:
-
GameObject
- Object
- BasicGameObject
- GameObject
- Chingu::Text
- Defined in:
- lib/chingu/text.rb
Overview
Text is a class to give the use of Gosu::Font more rubyish feel and fit it better into Chingu. Pure Gosu:
@font = Gosu::Font.new($window, "verdana", 30)
@font.draw("A Text", 200, 50, 55, 2.0)
Chingu
@text = Chingu::Text.new(:text => "A Text", :x => 200, :y => 50, :zorder => 55, :factor_x => 2.0)
@text.draw # usually not needed as Text is a GameObject and therefore autodrawn
Constant Summary collapse
- @@size =
nil
- @@font =
nil
Instance Attribute Summary collapse
-
#gosu_font ⇒ Object
readonly
Returns the value of attribute gosu_font.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from GameObject
#angle, #center, #center_x, #center_y, #color, #factor, #factor_x, #factor_y, #image, #mode, #x, #y, #zorder
Attributes inherited from BasicGameObject
#options, #parent, #paused, #visible
Class Method Summary collapse
- .font ⇒ Object
- .font=(value) ⇒ Object
- .height ⇒ Object
- .height=(value) ⇒ Object
- .size ⇒ Object
- .size=(value) ⇒ Object
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(options) ⇒ Text
constructor
Takes the standard GameObject-hash-arguments but also: - :text - a string of text - :font_name|:font - name of a systemfont (default: “verdana”) - :height|size - how many pixels high should the text be.
-
#width ⇒ Object
Returns the width, in pixels, the given text would occupy if drawn.
Methods inherited from GameObject
#distance_to, #inside_window?, #outside_window?
Methods included from Helpers::RotationCenter
Methods included from Helpers::InputClient
Methods inherited from BasicGameObject
all, create, #destroy, destroy_all, destroy_if, #draw_trait, has_trait, has_traits, #hide!, #pause!, #setup_trait, #show!, #unpause!, #update, #update_trait
Constructor Details
#initialize(options) ⇒ Text
Takes the standard GameObject-hash-arguments but also:
-
:text - a string of text
-
:font_name|:font - name of a systemfont (default: “verdana”)
-
:height|size - how many pixels high should the text be
34 35 36 37 38 39 40 41 |
# File 'lib/chingu/text.rb', line 34 def initialize() super() @text = [:text] || "-No text specified-" @font = [:font] || @@font || default_font_name() @height = [:height] || [:size] || @@size || 15 @gosu_font = Gosu::Font.new($window, @font, @height) end |
Instance Attribute Details
#gosu_font ⇒ Object (readonly)
Returns the value of attribute gosu_font.
16 17 18 |
# File 'lib/chingu/text.rb', line 16 def gosu_font @gosu_font end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
16 17 18 |
# File 'lib/chingu/text.rb', line 16 def height @height end |
#text ⇒ Object
Returns the value of attribute text.
15 16 17 |
# File 'lib/chingu/text.rb', line 15 def text @text end |
Class Method Details
.font ⇒ Object
20 |
# File 'lib/chingu/text.rb', line 20 def self.font; @@font; end |
.font=(value) ⇒ Object
21 |
# File 'lib/chingu/text.rb', line 21 def self.font=(value); @@font = value; end |
.height ⇒ Object
25 |
# File 'lib/chingu/text.rb', line 25 def self.height; @@size; end |
.height=(value) ⇒ Object
26 |
# File 'lib/chingu/text.rb', line 26 def self.height=(value); @@size = value; end |
.size ⇒ Object
23 |
# File 'lib/chingu/text.rb', line 23 def self.size; @@size; end |
.size=(value) ⇒ Object
24 |
# File 'lib/chingu/text.rb', line 24 def self.size=(value); @@size = value; end |
Instance Method Details
#draw ⇒ Object
43 44 45 |
# File 'lib/chingu/text.rb', line 43 def draw @gosu_font.draw_rot(@text, @x.to_i, @y.to_i, @zorder, @angle, @factor_x, @factor_y, @color, @mode) end |
#width ⇒ Object
Returns the width, in pixels, the given text would occupy if drawn.
50 51 52 |
# File 'lib/chingu/text.rb', line 50 def width @gosu_font.text_width(@text, @factor_x) end |