背景图像没有出现在Gosu上

时间:2016-09-04 03:03:04

标签: ruby libgosu

我现在正试图在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

1 个答案:

答案 0 :(得分:1)

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

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和名为&#34; startup_screen.png&#34;的便携式网络图形文件,此脚本加载800x600 gosu窗口,png文件对齐左上角角。