Created
August 18, 2009 03:35
-
-
Save shawn42/169516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_tile_set(actor, action) | |
actor_dir = Inflector.underscore(actor.class) | |
tileset = load_image "#{actor_dir}/#{action}.png" | |
action_imgs = [] | |
w,h = *tileset.size | |
if h > w | |
# down | |
num_frames = h/w | |
clip_from = Rubygame::Rect.new(0, 0, w, w) | |
clip_to = Rubygame::Rect.new(0, 0, w, w) | |
num_frames.times do | |
surface = Rubygame::Surface.new(clip_to.size) | |
tileset.blit surface, clip_to, clip_from | |
surface.set_colorkey(surface.get_at(0,0)) | |
action_imgs << surface | |
clip_from.y += w | |
end | |
else | |
# right | |
num_frames = w/h | |
clip_from = Rubygame::Rect.new(0, 0, h, h) | |
clip_to = Rubygame::Rect.new(0, 0, h, h) | |
num_frames.times do | |
surface = Rubygame::Surface.new(clip_to.size) | |
tileset.blit surface, clip_to, clip_from | |
surface.set_colorkey(surface.get_at(0,0)) | |
action_imgs << surface | |
clip_from.x += h | |
end | |
end | |
action_imgs | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment