Class: Xibe::Image
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#src_x ⇒ Object
Returns the value of attribute src_x.
-
#src_y ⇒ Object
Returns the value of attribute src_y.
Attributes inherited from Layer
#height, #visible, #width, #x, #y, #z
Class Method Summary collapse
-
.create(filename, transparent = false) ⇒ Object
Create a image.
-
.to_tiles(filename, width, height, transparent = false, margin = 0) ⇒ Object
Create a tiles from a image file.
Instance Method Summary collapse
-
#draw ⇒ Object
Draw image.
-
#initialize(filename, transparent = false) ⇒ Image
constructor
A new instance of Image.
Methods inherited from Layer
#bottom, #hide, #left, #pos, #right, #show, #top
Constructor Details
#initialize(filename, transparent = false) ⇒ Image
Returns a new instance of Image.
478 479 480 481 482 483 484 485 486 |
# File 'lib/xibe.rb', line 478 def initialize(filename, transparent=false) super() @filename = filename @image = Image.create(@filename, transparent) @width = @image.w @height = @image.h @src_x = 0 @src_y = 0 end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
476 477 478 |
# File 'lib/xibe.rb', line 476 def filename @filename end |
#src_x ⇒ Object
Returns the value of attribute src_x.
477 478 479 |
# File 'lib/xibe.rb', line 477 def src_x @src_x end |
#src_y ⇒ Object
Returns the value of attribute src_y.
477 478 479 |
# File 'lib/xibe.rb', line 477 def src_y @src_y end |
Class Method Details
.create(filename, transparent = false) ⇒ Object
Create a image
489 490 491 492 493 494 |
# File 'lib/xibe.rb', line 489 def self.create(filename, transparent=false) img = SDL::Surface.load(filename) color_key = img.get_pixel(0,0) img.set_color_key(SDL::SRCCOLORKEY ,color_key) if transparent == true img.display_format end |
.to_tiles(filename, width, height, transparent = false, margin = 0) ⇒ Object
Create a tiles from a image file
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/xibe.rb', line 497 def self.to_tiles(filename, width, height, transparent = false, margin = 0) img = create(filename, false) color_key = img.get_pixel(0,0) t_width = (img.w-margin) / (width + margin) t_height = (img.h-margin) / (height + margin) tiles = [] i = 0 while i < t_height do j = 0; while j < t_width do tiles << img.copy_rect(j*(width+margin)+margin, i*(height+margin)+margin, width, height) tiles[tiles.length - 1].set_color_key(SDL::SRCCOLORKEY, color_key) if transparent == true j += 1 end i += 1 end tiles end |
Instance Method Details
#draw ⇒ Object
Draw image
517 518 519 |
# File 'lib/xibe.rb', line 517 def draw SDL::Surface.blit(@image, @src_x, @src_y, @width, @height, SDL.get_video_surface, @x, @y) end |