/usr/local/lib/ruby/gems/2.2.0/gems/gosu-0.10.4/lib/gosu/patches.rb:37:in`initialize';:无法在gosu中打开文件./media/image.jpg(运行时错误)

/usr/local/lib/ruby/gems/2.2.0/gems/gosu-0.10.4/lib/gosu/patches.rb:37:in`initialize';:无法在gosu中打开文件./media/image.jpg(运行时错误),ruby,linux,libgosu,Ruby,Linux,Libgosu,我有这段代码,它没有给出所需的输出,并显示了上述错误 require 'gosu' def media_path(file) File.join(File.dirname(File.dirname( __FILE__)),'media', file) end #def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) # end class Explosion

我有这段代码,它没有给出所需的输出,并显示了上述错误

require  'gosu'

 def media_path(file)
   File.join(File.dirname(File.dirname(
    __FILE__)),'media', file)
 end


#def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__)
# end


 class Explosion
   FRAME_DELAY = 10 # ms
   SPRITE = media_path('space.png')

   def self.load_animation(window)
     Gosu::Image.load_tiles(
       window, SPRITE, 128, 128, false)
   end

   def initialize(animation, x, y)
     @animation = animation
     @x, @y = x, y
     @current_frame = 0
   end

   def update
     @current_frame += 1 if frame_expired?
   end

   def draw
     return if done?
     image = current_frame
     image.draw(
       @x - image.width / 2.0,
       @y - image.height / 2.0,
       0)
   end
 def done?
     @done ||= @current_frame == @animation.size
   end

   private

   def current_frame
     @animation[@current_frame % @animation.size]
   end

   def frame_expired?
     now = Gosu.milliseconds
     @last_frame ||= now
     if (now - @last_frame) > FRAME_DELAY
       @last_frame = now
     end
   end
 end

 class GameWindow < Gosu::Window
   BACKGROUND = media_path('image.jpg')

   def initialize(width=800, height=600, fullscreen=false)
     super
     self.caption = 'Hello Animation'
     @background = Gosu::Image.new(
       self, BACKGROUND, false)
     @animation = Explosion.load_animation(self)
     @explosions = []
   end

   def update
@explosions.reject!(&:done?)
     @explosions.map(&:update)
   end

   def button_down(id)
     close if id == Gosu::KbEscape
     if id == Gosu::MsLeft
       @explosions.push(
         Explosion.new(
           @animation, mouse_x, mouse_y))
     end
   end

   def needs_cursor?
     true
   end

   def needs_redraw?
     !@scene_ready || @explosions.any?
  end

   def draw
     @scene_ready ||= true
     @background.draw(0, 0, 0)
     @explosions.map(&:draw)
  end
 end

 window = GameWindow.new
 window.show
需要“gosu”
def介质路径(文件)
File.join(File.dirname(File.dirname(
__文件“,”媒体“,”文件)
终止
#def介质路径(文件);File.expand_路径“media/#{File}”,File.dirname(uu File_uu)
#结束
班级爆炸
帧延迟=10毫秒
SPRITE=media\u路径('space.png')
自定义加载动画(窗口)
Gosu::Image.load\u瓷砖(
窗口,精灵,128,128,假)
终止
def初始化(动画,x,y)
@动画=动画
@x、 @y=x,y
@当前帧=0
终止
def更新
@如果帧过期,当前帧+=1?
终止
def牵引
完成后返回?
图像=当前帧
图像绘制(
@x-image.width/2.0,
@y-图像高度/2.0,
0)
终止
完成了吗?
@完成| |=@current_frame==@animation.size
终止
私有的
def当前帧
@动画[@current_frame%@animation.size]
终止
def帧_已过期?
现在=Gosu.ms
@最后一帧| |=现在
如果(现在-@最后一帧)>帧延迟
@最后一帧=现在
终止
终止
终止
类GameWindow
它找不到。/media/image.jpg您确定它在那里,并且可以打开,并且是当前目录吗?“您认为它是什么?

请清理您的代码。。。只需在每个代码行的开头添加四个空格,以便将其格式化为代码。