0

我坐在这里,我认为这是一个非常简单的错误,我只是想不通.. 我试图学习如何使用 Ruby 使用 Gosu gem 制作游戏,但是遇到了减速带。这是我的代码。

require "gosu"

class Hello < Gosu::Window
    def initialize width = 800, height = 600, fullscreen = false
    super
    self.caption = "Ruby Practise"
    @image = Gosu::Image.from_text self. "My text to print".
                            Gosu.default_font_name.
                            100
    end
    def button_down id
        close if id == Gosu::KbEscape
    end
    def update
    end
    def draw
        @image.draw 0, 0, 0
    end
end
Hello.new.show

出了点问题,但我不知道是什么。我已经花了至少 1 个小时。它抱怨字符串,这是终端的输出。

hello.rb:8: syntax error, unexpected tSTRING_BEG
    @image = Gosu::Image.from_text self. "My text to print".
                                              ^
hello.rb:10: syntax error, unexpected tINTEGER

我不知道我做错了什么,有人知道吗?这可能是非常简单的事情..

4

1 回答 1

1

使用逗号分隔函数参数,而不是点:

@image = Gosu::Image.from_text self, "My text to print",
                        Gosu.default_font_name,
                        100
于 2015-01-15T03:21:39.897 回答