Not logged inGosu Forums
Forum back to Help Search Register Login
Up Forum
1 2 3 4 5 6 7 8 9 10 Previous Next  
Topic NameError By jlnr Date 2017-12-31 13:55
This little debug statement doesn't try to fix the issue, but it should print true or false in the terminal when you run the game, depending on whether the file can be found.
Topic NameError By jlnr Date 2017-12-31 13:53
Sorry for not replying earlier, but glad you found it :)
Topic Mir Server RuntimeError By jlnr Date 2017-12-22 11:20
Hmmm. What is your plan with Gosu running inside a Vagrant VM? Is the VM headless? That would explain why Gosu can't open a window. And why are you using a 3+ year old version of Ubuntu?
Topic NameError By jlnr Date 2017-12-22 11:17
You mean ruby game.rb, right? No idea. What does this print if you run this as the first line in your Ruby script:

p File.exist? "assets/starfighter.png"
Topic NameError By jlnr Date 2017-12-17 15:19
Do you have a folder assets next to the Ruby source code files, and does it contain an image named starfighter.png? How do you run your game?
Topic NameError By jlnr Date 2017-12-17 02:46
game.rb needs a require_relative 'player' at the top :)
Topic NameError By jlnr Date 2017-12-15 10:27
What does your code look like? Can you please attach your .rb file?
Topic Gosu 0.13.1 released By jlnr Date 2017-11-25 11:17
I've bumped the version because SampleInstance is now called Channel, and due to minor changes to the C++ interface.

• All: Brings draw_rect in line with other draw_ methods (available in C++, available on Gosu::Window in Ruby)
• All: SampleInstance is now called Channel, but the old name still works in Ruby
• All: Update the stb_image dependency to fix crashes when loading 1-bit PNG files
• Windows: Update bundled SDL to 2.0.7
• macOS: Work around a compiler bug in Xcode 9+
• C++: Image and Sample have a default constructor now that creates an "empty" object; minor interface changes
Topic undefined method 'draw_rect' By jlnr Date 2017-11-25 04:39
See also this issue:

This is exactly what happened, and yet I feel it's pretty confusing. Having to prefix methods with Gosu. does also not really feel like progress. Maybe Window subclasses (and others of course) could generally get around this by using include Gosu? I'll need to play around with this for a bit.
Topic Question about Gosu::Window#update_interval By jlnr Date 2017-10-21 16:33
update_interval (both the constructor argument, and the r/w property) controls the target framerate of Gosu. However, because Gosu usually waits for a vsync each frame, higher values than 60 (or whatever your screen uses) don't work.

The vsync part is actually becoming a bit of an issue. When I first wrote Gosu, CRT screens started being replaced by TFT flatscreens which all had a 60 Hz refresh rate, and I hoped that 60 Hz would be *the* standard framerate for a long time. But I've now received issue reports on GitHub from users with 40 Hz(!) laptop screens, and many desktop screens are running at 75 Hz all the way up to 144 Hz. And some unlucky people probably run their computer at 30 Hz because their HDMI cable can't do 4K at 60 Hz etc... Gosu's model of always running at 60 FPS is sadly not flexible enough for the reality of today's screens.

If you want to work with delta time, I suggest you use a really small value for update_interval, maybe 5, so that Gosu will max out the screen's Hz if possible. And then you measure the frame length yourself using Gosu.milliseconds (from one update call to the next), and move your objects accordingly.
Topic Slowdown during state switching step By jlnr Date 2017-10-08 08:23
You could try using a profiler to see what it is that keeps Ruby busy.

Rendering can only ever happen on the main thread. Even image loading is limited to the main thread right now:

It could be the garbage collector. If you create lots of temporary objects (usually tiny arrays and hashes) there might be stutter, but usually only a few 100 milliseconds.
Topic Correct way of using draw_as_quad By jlnr Date 2017-10-04 09:35
Ooohh never mind, apparently there is a solution:

Thanks for making me google this again! I've created a GitHub issue here:
Topic Correct way of using draw_as_quad By jlnr Date 2017-10-04 09:30
First, nice work!

What you are seeing is an unfortunate artifact of how OpenGL works - the distorted quads are split into two triangles, and textured independently. See this answer:

Basically, there is no way to have OpenGL fix these perspective issues for you without passing Z coordinates for each vertex, which Gosu does not support :/
Topic Including temporary Screenshots in Gosu By jlnr Date 2017-09-28 06:55
It's one of the most often requested features, here's the GitHub issue:

A workaround has recently been posted here:
Topic NeoGame - A Ruby game framework (early version) By jlnr Date 2017-09-25 08:26
Hi and welcome to Gosu! My #1 suggestion would be to see if you enjoy game-development competitions. I've found that they are great opportunities to work on game frameworks – that's how Gosu came into being :)
Topic Any way to get axial GP input? By jlnr Date 2017-09-03 20:32
Thanks, and glad to hear you're enjoying Gosu :)
Topic Any way to get axial GP input? By jlnr Date 2017-09-03 20:20
Hmm, what do you mean by axial? Are you looking for analog gamepad input (-1.0 ... +1.0)? Gosu still doesn't support this. I suggest opening an issue here:

...but generally, the fastest way to get it things/fixed is to send a Pull Request :)
Topic Input update interval By jlnr Date 2017-09-02 18:27
I'm not sure what kind of transition you are looking for, but this video shows a game that I've built with pure Gosu (in C++, but the code would look the same in Ruby - no C necessary):

(The first ten seconds are basically just different screens transitioning into each other. Ignore the rest, the game is dead now :))

The way I usually do it is that each screen (menu, dialog box, ...) is a different class/object and when a transition happens, I divide the number of ticks by total duration so that I end up with a number t between 0.0 and 1.0 as the "position" inside of the current transition. For example, if I wanted one screen to zoom in while another fades out, I would do this in draw:

def draw
  t = position_in_transition() # 0.0...0.1
  overlay_color = Gosu::Color.argb(t * 255, 0, 0, 0)
  Gosu.draw_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, overlay_color, 999999)
  Gosu.scale(t) { @next_screen.draw }
end's all possible, but you also have to do it all by yourself.
Topic Input update interval By jlnr Date 2017-09-02 16:54
There is no alternative, but of course you can write a helper method/class that wraps this and reuse it throughout your game.
Topic Gosu::Grid, passing draw an array By jlnr Date 2017-09-02 16:22
I haven't looked at the source code of the grid gem, but drawing a grid of things isn't hard to do in pure Ruby/Gosu. Maybe that's easier than getting the grid library to work. The Cptn Ruby example game contains a tiled map that works like a grid:
Topic Input update interval By jlnr Date 2017-09-02 16:02
You'll have to implement input delays in your game code. For example, if the player can hold the spacebar to keep shooting, you shouldn't create a new projectile every tick in Window#update when button_down? Gosu::KB_SPACE, since 60 bullets per second are probably too many. Instead, you should have a counter variable like @reload_time that you set to 30 when the player shoots, and then you decrement it every time update is called, and only when it reaches 0, you create another projectile. Now the player can shoot twice per second, and it will feel much nicer than if Gosu would only update button_down? every 500ms, because the first shot still happens immediately after pressing the button.

It's quite common for game objects in Gosu to have counter variables that count up or down until something happens.
Topic what happens when you call draw? By jlnr Date 2017-09-01 07:23
Gosu uses a pipeline so that it can implement Z-ordering, but this doesn't really affect performance here because the bottleneck is usually the game (Ruby), not Gosu (C++).

If you want to fill a full HD screen with 32x32 tiles, you'll need to call Image#draw 60*34=2040 times. The loop itself, with all the necessary calculations, can indeed be slow. You could use RMagick, but it's unwieldy and hard to install for anyone who wants to play your game.

Gosu offers Gosu.record(w, h) to solve this - the simplest way to use it is:

class SomeGridClass
  def draw
    # Only set this instance variable the first time this code is run...
    @cached_image ||= Gosu.record(width * 32, height * 32) do
      32.times do |y|
        32.times do |x|
          @some_tile.draw x * 32, y * 32, 0
    # @cached_image now contains a Gosu::Image with the width and height that was passed to record
    @cached_image.draw 0, 0, Z_MAP

Hope that helps.
Topic Gosu::Grid, passing draw an array By jlnr Date 2017-08-25 07:28
I've moved both topics to Gosu Exchange.

TIL that there's a gosu_grid gem :)
Topic Opening all the images in a folder and drawing (newbie) By jlnr Date 2017-08-17 19:16
In the above loop, x will be "10_of_clubs.png", but you cannot load"10_of_clubs.png") because the subdirectory is missing. Try"PNG-cards-1.3/" + x).

The Dir.glob approach works a little better in that regard because it will include the full path. I'm not sure why that didn't work, it should.
Topic Changing the way Font class works in Ruby By jlnr Date 2017-07-21 21:29
I don't want to add setters. I'm glad most objects in Gosu are immutable, it avoids a whole class of problems when people forget to reset a property after setting it to a temporary value, etc.

I do agree that the .draw methods (not just for Font) are extremely cumbersome. I still haven't looked into the new named arguments in Ruby 2.2+, maybe they can actually solve this nicely?

However, in the case you've mentioned (Font#draw), the three parameters are actually optional:
Topic OpenAL deleting buffers By jlnr Date 2017-07-21 21:24
This is on Linux, right? GitHub issue:

I've reopened it and tagged it as Help Wanted, in case anyone wants to look into this.
Topic Gosu and Ruby 2.4 on Windows - cannot load By jlnr Date 2017-06-20 10:22
Gosu 0.12.1 works with Ruby 2.4. \o/
Topic Gosu 0.12.1 released By jlnr Date 2017-06-19 21:34
A minor maintenance release for Windows users:

• Windows: Add support for Ruby 2.4 (#407)
• Windows: Fix MP3 playback on 32-bit systems (#405)

C++ and Mac/Linux users have no need to upgrade.
Topic Gosu and Ruby 2.4 on Windows - cannot load By jlnr Date 2017-05-31 19:09
This one's easy: Gosu does not support Ruby 2.4 on Windows yet, mostly because I didn't realise it has been released already. So thanks for pointing that out :)

I'll try to add Ruby 2.4 support ASAP, in the meantime, please downgrade to Ruby 2.3.
Topic Raspberry Pi music touchscreen By jlnr Date 2017-05-26 10:42
(Took me forever to get back to this post in my reading queue...)

That was really great timing with the MP3 patents expiring just in time for this project ;)

I didn't think it was possible to overheat the Pi though. Is it really the temperature? I've noticed flakiness on my Pi when I use a USB port that doesn't provide enough power. Has it worked OK in the long term?
Topic Create a Gosu::Image from clipboard By jlnr Date 2017-04-30 08:02
There is a Image.from_blob: You can pass an RMagick image instead of a filename to all Window constructors (also load_tiles etc.)

It doesn't really have to be an RMagick image, but it needs to respond to columns (width), rows (height) and to_blob (return RGBA data as a String). The problem is that you would still need to extract the width and height from the binary DIB image, and convert the RGB DIB data to RGBA.

If this is just for use during development, then I think saving the bitmap information to a temporary file and loading it back isn't such a bad option. It should be too fast to notice?
Topic Create a Gosu::Image from clipboard By jlnr Date 2017-04-27 19:21
Hah, interesting suggestion. There's no GitHub ticket for it yet, but I feel that clipboard support is definitely missing from Gosu's text editing.

My plan so far was this:
Gosu.clipboard returns the copied text or filename, or nil if the user hasn't copied anything useful. Games can just listen for ctrl+V/cmd+V and implement pasting of image files using the filenames. (Gosu::TextInput should have built-in copy & paste, though.) Writing to Gosu.clipboard= would allow for copying of arbitrary text.

I didn't even think of copying/pasting image data, though. Makes me wonder if a future Gosu.clipboard should be able to read/write Gosu::Image instances as well. Or maybe you could call it like this, image = Gosu.clipboard { |imgdata|, tileable: true) } if you are interested in image data, and without a block if you are interested in text.

What is the use case for pasting image data in a Gosu game? To quickly iterate on your game's assets? Maybe this hack will do the trick - pressing R in the window will cause all images to be reloaded from disk:
Topic Gosu 0.12.0 released By jlnr Date 2017-04-27 17:58
The limit is actually 1024x1024 with tileable: true, and 1022x1022 with tileable: false (because one row of empty pixels will be added at each side). I am just too lazy to type all of that every time :)

I was a bit worried that Drag & Drop might be unusual for a game framework, so it's great to hear that you enjoy the feature :) I'm looking forward to use it as well.
Topic Gosu 0.12.0 released By jlnr Date 2017-04-23 20:51
This version is mostly aimed at making Gosu less surprising - for example, MP3 files already worked on macOS and iOS, but not on Windows or Linux.

I've increased the minor version number because Gosu has a new dependency on Linux (libmpg123-dev).

* 2017-04-23: All: Image#subimage works for images larger than 1022x1022px (#398/#400).
* 2017-04-23: Windows, Linux: Support for MP3 files (#397).
* 2017-04-22: C++: Use std::function parameters instead of begin/end function pairs (#399).
* 2017-04-04: Raspberry Pi: Use correct OpenGL version on Pi 2 & 3.
* 2017-03-29: All: Add Window#drop(filename) callback for when the user drops a file onto the window (#378/#382). Thanks @Kjarrigan!
* 2017-03-27: All: Fix an inconsistency in Color#from_hsv (#359).
Topic Problem Installing Gosu on Raspberry Pi By jlnr Date 2017-04-05 19:59
It turns out that getting Gosu to work on the Pi 2 and 3 is much easier than on the original Pi. Basically, just enable OpenGL and then install Gosu as you would on a normal Linux distro (but be sure to sudo gem install gosu --pre until 0.11.4 is out).

Probably too late, but maybe it'll be helpful for the next person looking into this.
Topic Gosu 0.11.3 [and] released By jlnr Date 2017-03-26 21:49
Oops. I've had to push to hotfix an issue with legacy button constants on Ruby.
Topic Gosu 0.11.3 [and] released By jlnr Date 2017-03-26 11:17
Some fixes, but also a new feature: Gosu::Window instances can avoid being closed immediately by overriding close. For example, you might want to ask the user if they want to save their current game before exiting.

• Ruby: Add deprecation warnings for many old methods (thanks @Kjarrigan)
• Windows: Fix an encoding issue when the current user has a non-ASCII username
• Windows: TTF files can be loaded using relative paths
• All: Window#close can be overridden to prevent the user from closing the window immediately; call close! to immediately close the Window in Ruby (thanks @Kjarrigan)
• macOS: Fix TTF font file loading
• All: Image#subimage is now part of Gosu's official API
Topic Gosu::Image.subimage and performance By jlnr Date 2017-03-12 16:33
I've removed the comment about it being experimental 🎉 It's now a proper part of Gosu.

A note on your gist: The image does not have to be a power-of-two for subimage to work. Gosu will copy the image to a 1024x1024px texture and use the remaining space for other textures.

But the image must not be larger than 1024x1024px. Beyond that, Gosu will split it up into several 1024x1024px textures automatically, and then subimage will stop working. (This is actually a limitation that I could work around. Hmm. Maybe in a future version...) You could add a check for that in the constructor to prevent surprises.
Topic Gosu::Image.subimage and performance By jlnr Date 2017-03-02 16:40
Good news: Image#subimage is extremely fast. So fast that you could recreate the subimages every tick, draw them once, and then discard them.

The difference between Image#subimage and loading an image via the constructor is that the latter will add padding around the image when copying it to an OpenGL texture. Those pixels will either be translucent (default) or repeat the outermost colour values (tileable: true). That ensures that the image looks good when scaling, rotating etc.

With subimage, it is your responsibility to make sure the images have some padding. (If you use retro: true, this doesn't matter.)

If you are worried about performance, you can just pre-process the tile sheets with RMagick or another image library, and then either use load_tiles or subimage depending on what suits you better.

By the way: All of the image constructors (including Image.load_tiles) dynamically build a tile atlas on 1024x1024px GL textures. You can observe whether images end up on the same texture internally by comparing image.gl_tex_info.tex_name.
Topic Gosu 0.11.1 released By jlnr Date 2017-02-26 10:55
Thanks :) I've just release version 0.11.2 to fix the issue.
Topic Gosu 0.11.2 released By jlnr Date 2017-02-26 10:50
This is a belated hotfix release for some issues introduced in Gosu 0.11.x:

• Ruby: Arguments are automatically converted to String everywhere
• Ruby: Fix name of mouse position setters
• All: Reset current colour to solid white before running GL blocks
• Ruby: Fix handling of exceptions in Window#needs_redraw? (#376)
Topic StickBall how to correct alpha with current Gosu version? By jlnr Date 2017-02-26 10:47
Sorry for the long delay, I have been travelling. You have probably tried to change a predefined colour:

color = Gosu::Color::RED
color.alpha = 5

Gosu prevents changes to colour constants, but this is not documented and the error message is pretty misleading. The correct way to fix this is:

color = Gosu::Color::RED.dup
color.alpha = 5
Topic Gosu 0.11.1 released By jlnr Date 2017-02-11 13:43
Ouch! They might have disappeared when I renamed the C++ equivalents. I'll investigate in the next weeks, life is busy right now :)
Topic The "Vulkan" Thread By jlnr Date 2017-02-06 14:33
I think better support for OpenGL ES is the lower-hanging fruit; a few #ifdefs here and there, and Gosu would work on every system which either supports OpenGL or OpenGL ES, which seems to cover almost everything. Right now, Gosu already uses OpenGL ES 1.x on iOS and on the Raspberry Pi, and full OpenGL everywhere else.
Topic RubyConf 2016 talk By jlnr Date 2017-02-06 12:57
Hah. Glad you enjoyed it :) I had a lot of fun collecting these videos - I hadn't even heard of most presentations before.
Topic Ruby Chipmunk Integration beginner hacking gosu-example By jlnr Date 2017-02-01 06:44
Thanks for reporting back. I've linked the PhilCK/Chipmunk-Examples repo from the Ruby-Chipmunk-Integration wiki page, so helpfully it will be easier to find for the next developer.
Topic Gosu 0.11.1 released By jlnr Date 2017-02-01 06:25
Ashton now lives in the Gosu organisation on GitHub, so it's something I can and will fix at some point (possibly by moving functionality into Gosu proper).

ocra is another gem that seems to be mostly dormant, and which Gosu relies on...

But it's good news that Ruby 1.9.3 is still around, and I'll take extra care not to break compatibility with Ruby 1.9.x. (It seems safe to kick out Ruby 1.8 support, though.)
Topic Gosu 0.11.1 released By jlnr Date 2017-01-30 12:30

> because I assume that in a clean brand new environment, it is by default set to white

I was thinking about that too after posting my reply. gl blocks are supposed to give you a clean environment, so I think that was a bug (or at least unintuitive). Gosu 0.11.2+ will automatically reset the colour before running a gl block; not sure when that version will be out, though.
Topic Gosu 0.11.1 released By jlnr Date 2017-01-30 02:22
Well, the good news is, the texture is definitely not being purged. You can check by calling"test.png"), which will use OpenGL internally to download the texture data before saving it to a file.

And I just managed to find the bug. When you use fullscreen mode, Gosu uses black bars to preserve the window's aspect ratio. Since you do not reset it, all vertices will appear black as well. It works if you add glColor4f(1, 1, 1, 1) in CubeModel#draw.

Yay, no Gosu bug :) - which is great because I won't have time for a release in February.
Topic Gosu 0.11.1 released By jlnr Date 2017-01-30 02:16
=( I wasn't even aware that Ruby on Windows was so broken until I tried to run gosu-examples with Ruby 2.3 last week. I couldn't get OpenGL to install, and Chipmunk was extremely crashy. I wonder if it'll get worse now that Rails developers can use the Ubuntu subsystem on Windows 10 instead of Ruby-Installer.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill