Class: Chronus::Image
- Inherits:
-
Object
- Object
- Chronus::Image
- Defined in:
- lib/chronus/image.rb
Class Method Summary collapse
- .create(filename, transparent = false) ⇒ Object
- .to_tiles(filename, width, height, transparent = false, margin = 0) ⇒ Object
Class Method Details
.create(filename, transparent = false) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/chronus/image.rb', line 6 def self.create(filename, transparent=false) img = 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
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/chronus/image.rb', line 13 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 |