Skip to content

Instantly share code, notes, and snippets.

@RPGP1
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RPGP1/9563385 to your computer and use it in GitHub Desktop.
Save RPGP1/9563385 to your computer and use it in GitHub Desktop.
AnimationRenderTarget完成した!
#coding: UTF-8
require 'dxruby'
module DXRuby
def self.image?(v)
Image === v || RenderTarget === v
end
module Animation
attr_reader :bgimages, :index
@@array_of_animation_render_target = []
def self.update
Sprite.update(@@array_of_animation_render_target)
end
Window.after_call[:update_array_of_animation_render_target] = self.method(:update)
def initialize(width, height, bgimages, bgcolor=[0,0,0,0], interval: 1, index: 0, step: 1)
super(width, height, bgcolor)
@bgimages = bgimages.dup.keep_if{|x| DXRuby.image?(x)}
@count = @interval = interval
@index = index
indexCheck
@step = step
@@array_of_animation_render_target << self
end
def update
@count -= 1
if @count < 0
@index += @step
indexCheck
@count = @interval
end
unless @bgimages.empty?
self.draw(0,0,@bgimages[@index],-10000)
end
super
end
def vanish
super
@@array_of_animation_render_target.delete(self)
end
def index=(v)
@index = v
indexCheck
@index
end
def bgimages=(v)
@bgimages = v.dup.keep_if{|x| DXRuby.image?(x)}
end
private
def indexCheck
@index = @index.to_i #整数にする
while @index < 0 #小さすぎる間は
if @bgimages.empty?
@index = 0
else
@index += @bgimages.size
end
end
while @index >= @bgimages.size #大きすぎる間は
if @bgimages.empty?
@index = 0
else
@index -= @bgimages.size
end
end
end
end
class AnimationRenderTarget < RenderTarget
include Animation
end
ART = AnimationRenderTarget
end
font = Font.new(32)
arr = Array.new(10){|i| Image.new(32, 32).drawFont(8,0,i.to_s,font)}
art = ART.new(32,32,arr,interval:15)
Window.loop do
art.draw(0,0,Image.new(1,1,C_WHITE))
Window.draw(0,0,art)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment