I’m trying to use the PixbufSimpleAnim, to show a animation generated by
multiple image files. The problem is that the animation runs once, and
then stops.
I saw in the samples that a gif file loaded using PixbufAnimation gives
me a looping animation. How can I accomplish the same result using a
PixbufSimpleAnim?
I’m trying to use the PixbufSimpleAnim, to show a animation generated by
multiple image files. The problem is that the animation runs once, and
then stops.
I saw in the samples that a gif file loaded using PixbufAnimation gives
me a looping animation. How can I accomplish the same result using a
PixbufSimpleAnim?
Ok, I wrote a little class that does the animation. You can use it as a
simple image, just pass the frames as a array of pixbufs in the
initialization:
def restart(frames=[], fps=60, frame_time=1) @frames, @fps, @frame_time = frames, fps, frame_time @running = false @t.join if @t
start_animation
end
def fps=(i) @fps = i
start_animation
end
def frame_time=(i) @frame_time = i
start_animation
end
private
def start_animation
return if not @frames or @fps == 0 or @frame_time < 1
return if @frames.length == 0
@running = true
i = 0
@t = Thread.new do
while @running and not self.destroyed?
self.pixbuf = @frames[i]
i += 1
i = 0 if i == @frames.length
sleep 1.0 / @fps.to_f * @frame_time.to_f
end
end