Skip to content

Instantly share code, notes, and snippets.

@aoitaku
Created December 9, 2015 13:49
Show Gist options
  • Save aoitaku/93d0fd2c347f5990feb3 to your computer and use it in GitHub Desktop.
Save aoitaku/93d0fd2c347f5990feb3 to your computer and use it in GitHub Desktop.
DXRuby::Animative
require_relative 'anime_sprite'
module DXRuby
class Animation < Struct.new(:animation_image, :motions)
end
module Animative
class Motion < Struct.new(:name, :delay, :pattern)
end
def self.animator=(animator)
@animator = animator
end
def self.animize(sprite, animation)
return unless DXRuby::Animation === animation or Array === animation or String === animation
case animation
when Array
animation = @animator.create_from_array(animation)
when String
animation = @animator.load(animation)
end
sprite = AnimeSprite.new(sprite.x, sprite.y, sprite.image) unless AnimeSprite === sprite
sprite.tap {|sprite|
animation.motions.each {|motion|
sprite.add_animation(motion.name, motion.delay, motion.pattern)
}
sprite.animation_image = animation.animation_image
sprite.image = sprite.animation_image[animation.motions.first.pattern.first]
sprite.start_animation(animation.motions.first.name)
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment