Class: MovieMaker::Rubygame::TTFSprite

Inherits:
Object
  • Object
show all
Includes:
Rubygame::Sprites::Sprite
Defined in:
lib/movie_maker/sprite.rb

Overview

TTRSprite creates a rubygame sprite from a string/font Use this if you wanna move,rotate and zoom texts/letters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, options = {}) ⇒ TTFSprite

Returns a new instance of TTFSprite.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/movie_maker/sprite.rb', line 49

def initialize(string, options={})
	super()
	@string = string
	@color = options[:color] || Color[:black]
	@size = options[:size] || 15
	@position = options[:position] || [0,0]
	@fontname = options[:fontname] || "FreeSans.ttf"
	@font = options[:font] || nil
	
	if @font.nil?
		@font = TTF.new(File.join("fonts", @fontname), @size)
	end
	
	@rect = Rect.new(@position[0], @position[1], *@font.size_text(string))
	@image = Surface.new(@rect.size, 0, [SRCCOLORKEY])
	@font.render(@string, true, @color).blit(@image,[0,0])
	@image.set_colorkey(@image.get_at(0,0))
	
	@angle = 0.0
	@width_scaling = 1.0
	@height_scaling = 1.0
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



48
49
50
# File 'lib/movie_maker/sprite.rb', line 48

def angle
  @angle
end

#height_scalingObject

Returns the value of attribute height_scaling.



48
49
50
# File 'lib/movie_maker/sprite.rb', line 48

def height_scaling
  @height_scaling
end

#imageObject (readonly)

Returns the value of attribute image.



47
48
49
# File 'lib/movie_maker/sprite.rb', line 47

def image
  @image
end

#rectObject

Returns the value of attribute rect.



48
49
50
# File 'lib/movie_maker/sprite.rb', line 48

def rect
  @rect
end

#width_scalingObject

Returns the value of attribute width_scaling.



48
49
50
# File 'lib/movie_maker/sprite.rb', line 48

def width_scaling
  @width_scaling
end

Instance Method Details

#realign_centerObject



80
81
82
83
84
# File 'lib/movie_maker/sprite.rb', line 80

def realign_center
	old_center = @rect.center
	@rect.size = @image.size
	@rect.center = old_center
end

#xObject



76
# File 'lib/movie_maker/sprite.rb', line 76

def x;					@rect.centerx;					end

#x=(value) ⇒ Object

Rubygame X/Y setters/getters



75
# File 'lib/movie_maker/sprite.rb', line 75

def x=(value); 	@rect.centerx = value;	end

#yObject



78
# File 'lib/movie_maker/sprite.rb', line 78

def y;					@rect.centery;					end

#y=(value) ⇒ Object



77
# File 'lib/movie_maker/sprite.rb', line 77

def y=(value); 	@rect.centery = value;	end