Skip to content

Instantly share code, notes, and snippets.

@shawn42
Created August 18, 2009 03:35
Show Gist options
  • Save shawn42/169516 to your computer and use it in GitHub Desktop.
Save shawn42/169516 to your computer and use it in GitHub Desktop.
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