0

我现在正在尝试用 Gosu 和 Ruby 创建一个游戏。我遇到了一个问题,即我的代码中没有显示背景图像。我没有收到任何错误,但是每当我启动应用程序时,我都会出现黑屏,我很困惑为什么,有人可以帮忙吗?

require 'gosu'
require_relative 'player'
require_relative 'enemy'
require_relative 'bullet'
require_relative 'eb_bullet'
require_relative 'explosion'

class SectorFive < Gosu::Window
 WIDTH = 800
 HEIGHT = 600
 ENEMY_FREQUENCY = 0.03
 ENEMY_BULLET_FREQUENCY = 0.009
 def initialize
  super(WIDTH, HEIGHT)
  self.caption = "Sector Five"
  @background_image = Gosu::Image.new('images/start_screen.png')
end


def draw
 @background_image.draw(0,0,0)
end
end
window = SectorFive.new
window.show
4

1 回答 1

1

您的缩进很尴尬,您需要update在 SectorFive 类中使用一个方法,例如

require 'gosu'
#require_relative 'player'
#require_relative 'enemy'
#require_relative 'bullet'
#require_relative 'eb_bullet'
#require_relative 'explosion'

class SectorFive < Gosu::Window
#  ENEMY_FREQUENCY = 0.03
#  ENEMY_BULLET_FREQUENCY = 0.009

  def initialize(width=800, height=600)
    @width     = width
    @height    = height
    super width, height, false    # <-- fullscreen = false
    self.caption = "Sector Five"
    @background_image = Gosu::Image.new('images/start_screen.png')
  end

  def update                      # <-- updates @60hZ; game logic goes here
  end

  def draw
    @background_image.draw(0,0,0)
  end

end

window = SectorFive.new
window.show

...带有一个子目录images和一个名为“startup_screen.png”的可移植网络图形文件,此脚本加载一个 800x600 的 gosu 窗口,其中 png 文件对齐到左上角。

于 2016-10-05T01:48:34.177 回答