我正在尝试运行此脚本,而我正在使用Coderunner 2
require 'rubygems'
require 'gosu'
class Ball
def initialize(the_window)
@x = 200
@y = 200
@w = 20
@h = 20
@image = Gosu::Image.new(the_window, "ball.png", false)
end
def draw
@image.draw(@x, @y , 1)
end
end
class GameWindow < Gosu::Window
def initialize
super 800,600, false
self.caption = "Paddle Game"
@ball = Ball.new(self)
end
def update
end
def draw
@ball.draw
end
end
window = GameWindow.new
window.show
**
它启动了一条错误消息:
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require':
cannot load such file -- gosu (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in
`require'
from paddle_game.rb:2:in `<main>'
我安装了Ruby 2.0.0和宝石......当我尝试安装gosu时,这是我得到的错误:
Mac-Users-iMac-763:~ macuser$ sudo gem install gosu
Building native extensions. This could take a while...
ERROR: Error installing gosu:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r . /siteconf20151124-93492-9a029w.rb extconf.rb
The Gosu gem requires some libraries to be installed system-wide.
See the following site for a list:
https://github.com/jlnr/gosu/wiki/Getting-Started-on-OS-X
creating Makefile
current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
make "DESTDIR=" clean
current directory: /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4/ext/gosu
make "DESTDIR="
compiling stb_vorbis.c
compiling gosu_wrap.cxx
compiling Audio-Audio.cpp
compiling Bitmap-Bitmap.cpp
compiling Bitmap-BitmapIO.cpp
compiling DirectoriesUnix.cpp
compiling FileUnix.cpp
compiling Graphics-BlockAllocator.cpp
compiling Graphics-Color.cpp
compiling Graphics-Graphics.cpp
compiling Graphics-Image.cpp
compiling Graphics-LargeImageData.cpp
compiling Graphics-Macro.cpp
compiling Graphics-Resolution.cpp
compiling Graphics-ResolutionApple.cpp
compiling Graphics-TexChunk.cpp
compiling Graphics-Texture.cpp
compiling Graphics-Transform.cpp
compiling Input-Input.cpp
compiling Input-TextInput.cpp
compiling Inspection.cpp
compiling IO.cpp
compiling Math.cpp
compiling Text-Font.cpp
compiling Text-Text.cpp
compiling Text-TextApple.cpp
compiling TimingApple.cpp
compiling Utility.cpp
compiling UtilityApple.cpp
compiling Window.cpp
linking shared-object gosu.bundle
clang: error: unknown argument: '-multiply_definedsuppress'
make: *** [gosu.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/gosu-0.10.4
for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-
13/2.0.0/gosu-0.10.4/gem_make.out
我试图研究和提出不同的建议,但我现在无法进一步研究。只是想知道我可能做错什么或者我应该使用不同的编辑器吗?不确定为什么'要求'不适合我。感谢
答案 0 :(得分:0)
我发现了一些事情:
class Ball
缩进了一个空格。 end
class Ball
方法。 end
功能后,您还有def draw
个。{/ li>
require 'rubygems'
这个版本的代码在我的系统上启动了一个窗口(Ubuntu 14使用Ruby 2.3并使用rvm 1.11.3.9我已下载并bundled gosu 0.10.8):
# require 'rubygems'
require 'gosu'
# class Ball
# def initialize(the_window)
# @x = 200
# @y = 200
# @w = 20
# @h = 20
# @image = Gosu::Image.new(the_window, "ball.png", false)
# end
# end
#
# def draw
# @image.draw(@x, @y , 1)
# end
# end
class GameWindow < Gosu::Window
def initialize
super 800, 600, false # <-- width, height, fullscreen=false
self.caption = "Paddle Game"
# @ball = Ball.new(self)
end
def update
end
def draw
# @ball.draw
end
end
window = GameWindow.new
window.show
如果您在OSX上使用Ruby Gosu,您可能希望转到此处:
https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X
对于它的价值,我得到了相同的&#34; LoadError&#34;安装完成后使用&#34; bundler&#34;在项目目录中处理了gem依赖项。我访问了GOSU网站的Linux版本:
https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux
并在命令行中输入后:
user@ubuntu:~/Ruby/gosu_project$ sudo apt-get install build-essential libsdl2-dev libsdl2-ttf-dev libpango1.0-dev libgl1-mesa-dev libfreeimage-dev libopenal-dev libsndfile-dev
user@ubuntu:~/Ruby/gosu_project$ gem install gosu
我还必须调用:
user@ubuntu:~/Ruby/gosu_project$
的束强>
http://bundler.io/ - 也适用于MacOSX ......
per:https://github.com/gosu/gosu/wiki/ruby-tutorial
这个gosu文件:
# basic Gosu: gui test file
require 'gosu'
class TestWindow < Gosu::Window # <-- inherits from Gosu Window Super class
def initialize
super 640, 480, false # <-- width, height, fullscreen = false
self.caption = "successful gosu test window"
end
def update
end
def draw
end
end
TestWindow.new.show
...加载640x480窗口
user@ubuntu:~/Ruby/gosu_project$ ruby gosu_test.rb