Class: Gosling::Sprite
Overview
This type of Actor accepts a Gosu::Image to be rendered in place of the standard flat-colored shape. It behaves very much like a Rect, except its width and height are automatically set to the width and height of the image given to it and cannot be modified otherwise. The image can be changed at runtime. Changing this actor’s color or alpha applies tinting and transparency to the image rendered.
Instance Attribute Summary
Attributes inherited from Rect
Attributes inherited from Actor
#are_children_tangible, #are_children_visible, #children, #color, #is_mask, #is_tangible, #is_visible, #parent, #window
Attributes included from Transformable
Instance Method Summary collapse
-
#get_image ⇒ Object
Returns the image currently assigned to this Sprite.
-
#initialize(window) ⇒ Sprite
constructor
A new instance of Sprite.
-
#set_image(image) ⇒ Object
Assigns the image to this Sprite, setting its width and height to match the image’s.
Methods inherited from Polygon
#get_global_vertices, #get_vertices, #is_point_in_bounds, #set_vertices, #set_vertices_rect
Methods inherited from Actor
#add_child, #alpha, #alpha=, #blue, #blue=, #draw, #get_actor_at, #get_actors_at, #get_global_position, #get_global_transform, #green, #green=, #has_child?, #inspect, #is_point_in_bounds, #red, #red=, #remove_child
Methods included from Transformable
#center, #center=, #center_x, #center_x=, #center_y, #center_y=, #reset, #scale, #scale=, #scale_x, #scale_x=, #scale_y, #scale_y=, #to_matrix, transform_point, #transform_point, #translation, #translation=, untransform_point, #untransform_point, #x, #x=, #y, #y=
Constructor Details
#initialize(window) ⇒ Sprite
Returns a new instance of Sprite.
11 12 13 14 15 |
# File 'lib/gosling/sprite.rb', line 11 def initialize(window) super(window) @image = nil @color = Gosu::Color.rgba(255, 255, 255, 255) end |
Instance Method Details
#get_image ⇒ Object
Returns the image currently assigned to this Sprite.
20 21 22 |
# File 'lib/gosling/sprite.rb', line 20 def get_image @image end |
#set_image(image) ⇒ Object
Assigns the image to this Sprite, setting its width and height to match the image’s.
27 28 29 30 31 32 |
# File 'lib/gosling/sprite.rb', line 27 def set_image(image) raise ArgumentError.new("Expected Image, but received #{image.inspect}!") unless image.is_a?(Gosu::Image) @image = image self.width = @image.width self.height = @image.height end |