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 Simple card memory game demo By jlnr Date 2016-08-01 19:28

> Re: the distribution thing, you should check out Releasy. There's a link on the Gosu homepage.

I would like to add: if you get stuck using Releasy, you can also try using Ocra first (Releasy wraps the Ocra tool, among others). Ocra is conceptually simple - all it does is to stuff your game into a self-extracting EXE file that will run your game out of a temporary folder. If everything works with Ocra but not with Releasy, you know it's an issue with your Releasy configuration.
Topic Simple card memory game demo By jlnr Date 2016-08-01 19:21
I haven't run the game, only scrolled over it on GitHub, but this is what I noticed:

It is not necessary to spell out the ".rb" when using require or require_relative:

Because there's usually only one Window, you don't need to use @@class_variables here:
Likewise, $current_room doesn't need to be a global variable, I think.

You don't need the {} around hash argument lists:
Just, :name => "foo") is enough.

When you call Window#close, it's usually best to return from the method (instead of forwarding the button press, in this case):

Loading each image individually leads to a lot of copy & paste here:
Probably better to create these images from an array of names:
%w(camel-head donkey frog ...).each_with_index do |name, index|
  @images[index + 1] ="images_animals/#{filename}.png", :retro => true)

This can be simplified to if @cards.compact.empty?:
I think the design of this method is unconventional too, it both answers a question (is the game over?) as well as setting the best_time. I'd rename it to game_ended? and move the assignment to best_time into button_up, into the if game_ended... block.

Most of it is nitpicking, but I think that's what you asked for - hope that helps :)

You could also try the Rubocop tool for (very superficial) feedback on the way you format and structure your code. I don't agree with its default settings at all, but sometimes it'll point out something useful.

Edit: One more thing, you might want to look into Bundler and commit the Gemfile and Gemfile.lock. That way, it is clear (without reading the README) which version of Gosu you used to develop your game. This makes it a lot easier to other people to debug issues such as running the game with a version of Gosu that's too old (say, 0.7.50). This applies to all sorts of Ruby projects.
Topic get clicked pixel color By jlnr Date 2016-07-20 20:01
Yes, but enable_undocumented_retrofication was a only temporary hack while I was working on the :retro flag, which is the new way of doing things:"filename.png", retro: true)
Topic get clicked pixel color By jlnr Date 2016-07-05 23:36
You can use gl_tex_info to read out the pixels in an image using OpenGL, but that's exactly what Image#to_blob is doing for you, except that you need an extension to make use of gl_tex_info (the opengl gem).

The Image#[] method I've linked to is the exact equivalent of the Löve2D function you've mentioned. But if you need a way to read out an individual image's pixels _under the mouse cursor_, you also need to know where each image has been drawn. You can't take a screenshot of the window and read individual pixels from that (at least not without extensions).

When implementing a Risk map, you have all the information you need: An image for each country plus its x/y coordinate on the world map. When the user clicks, you can iterate over all your images and read out the pixel using @country_image[(mouse_x - @image_left).to_i, (mouse_y - @image_top).to_i]. If pixel[3].ord != 0, the pixel is not transparent.

(I've extended Image#[] with some bounds checking in the old post I've linked to above. Also, :retro only sets a few OpenGL parameters that change how the image is rendered when it is stretched or rotated, it does not affect the image's pixel data.)
Topic get clicked pixel color By jlnr Date 2016-07-05 16:31
This question came up just last month, hidden in this thread:

You will still need to remember which image was drawn at which position, though.
Topic Any way for a file drag and drop ? By jlnr Date 2016-06-20 19:37
There is an SDL event we could use for this:

...but I would still prefer it if a Ruby GUI toolkit finally emerged that handled all of this for us :(

If you only need to do this on Windows, you can probably use the funky win32-api gem to install a hook of type WH_CALLWNDPROC:

And then when you receive the WM_DROPFILES message, you need to call the Drag* functions to figure out the filename:

It will be either easy or hard depending on how familiar you are with this gem :)

Edit: It turns out that the DragQueryFile function is already defined in this companion gem:

And here is someone who has successfully used SetWindowsHookEx with the win32-api gem:
Topic How's Gosu Work In Mobile Game By jlnr Date 2016-06-17 17:32
Hmm, kind of, but only for OS X:

I guess I should turn this into a "Getting Started with RubyMotion" page in the main Gosu wiki. It's on the To Do list, let's hope my three days off will be enough to get to it :)
Topic How's Gosu Work In Mobile Game By jlnr Date 2016-06-17 17:24
Oh wow, I didn't know about this tutorial :) The version numbers look a little ancient though, and the last commits on gosu_android have happened years ago:

But if you are going to give it a try, let me know how it goes. I will probably give RubyMotion's implementation of Ruby a try first, because I have heard quite a few bad things about Ruboto's startup time.
Topic [] Can't set an avatar By jlnr Date 2016-06-17 17:16
Thanks! I've put it on my To Do list (which doesn't mean too much :(). As a workaround, you should be able to use to set an avatar.
Topic How's Gosu Work In Mobile Game By jlnr Date 2016-06-15 09:20
Good question. I'd probably cut my rate to something like 40€/h because I'm working on Open Source, yay! (But not lower because I expect JNI/GC debugging to be painful :))

Considering that my own macOS/iOS RubyMotion game is only half finished and no one else has ever used RubyMotion with Gosu on an App Store, I'm wary of making any guarantees. A good first step would be to compile your game for RubyMotion on iOS, I think you can even deploy on device now with the free edition? That might give you (and me!) an idea of how stable that part of Gosu is right now.
Topic How's Gosu Work In Mobile Game By jlnr Date 2016-06-12 11:31
If by mobile you mean iPhone and iPad:

The C++ version works the same way it works on OS X, by creating a new Xcode project and importing Gosu via CocoaPods:

The Ruby version can be used on iOS with RubyMotion, which is free if you can live with a branded splash-screen. This (woefully incomplete/ugly) board game on GitHub has an example project in the ios folder:

I honestly don't even know where to start documenting either process, so feel free to just ask questions on this board and I might turn the answers into Wiki pages.

Android is not supported right now. I guess it'd take one weekend to get the C++ version running smoothly on Android, and then a full week to wrap it for RubyMotion.
Topic Issue with for Ruby / Gosu games By jlnr Date 2016-06-05 20:51
Works on my Mac, same OS. If you open a Terminal and run, do you see anything that could explain the issue?

I'll also try it in a fresh OS X VM that doesn't have any developer stuff installed.
Topic Gosu and automake By jlnr Date 2016-05-23 10:13
To be honest, I'm not sure. Most people (including me) only seem to be using Ruby/Gosu on Linux, not the C++ version.

How are games on Linux usually distributed? I guess I should finally install Steam in my Linux VM...

The cleanest way (to me) would be to build a .deb archive for both Gosu and your game, for which there is a shell script in the cmake/ folder that I haven't really tested. That should at least cover all Debian derivates.
Topic Gosu 0.10.7 released By jlnr Date 2016-05-22 20:26
np :)
Topic Gosu 0.10.7 released By jlnr Date 2016-05-22 15:59
Yep, the ||= operator does the caching here.

It will work for any image (except record-ed ones), unlike gl_tex_info etc. which can fail for very large images.
Topic Gosu 0.10.7 released By jlnr Date 2016-05-21 22:32
If all you need is get_pixel, then you can probably just load a Gosu::Image, call to_blob on it (be sure to cache the result) and parse the binary data. Something like:

class Gosu::Image
  def [](x, y) # Returns a binary string with r/g/b/a as the characters
    @blob ||= self.to_blob
    if x < 0 or x >= width or y < 0 or y >= height
      "\0\0\0\0" # return transparent pixels by default; you could also return nil
      @blob[(y * width + x) * 4, 4]
some_image[x, y] # to read a pixel
Topic Gosu + RubyMotion? By jlnr Date 2016-05-21 09:02
If anyone is still finding this thread via Google - Gosu has supported RubyMotion for a while now, check out this example project:

It's a normal MRI project, and there are RubyMotion wrapper projects in osx/ and ios/. They use the RubyMotion-CocoaPods bridge to install C++ Gosu. (No Android, sorry...)
Topic Gosu and automake By jlnr Date 2016-05-21 08:42
Hm, I actually thought the CMake setup would build a static library, but that doesn't seem to be the case. Sorry!

I know nothing about autoconf, but you should be able to use a system-wide Gosu installation in every unixy build system by passing pkg-config --cflags gosu and pkg-config --libs gosu to the compiler and linker, respectively.
Topic (Small?) Feature Request By jlnr Date 2016-05-21 08:36
I've replied to the this feature request on GitHub:

Writing a Shape class that imitates Gosu::Image shouldn't be too hard based on Gosu.draw_quad, which does not need the Window reference :)
Topic Gosu 0.10.7 released By jlnr Date 2016-05-20 23:17
The biggest improvement in Ruby 2.0 for me was not ever having to start files with # Encoding: UTF-8 ever again :) (UTF-8 is the default now.)

Ruby 2.1/2.2 have introduced new syntax for named arguments, but I haven't really seen them in the wild yet.
Topic Inuhh Shinvasion - Yet another jump'n'run By jlnr Date 2016-05-09 14:03
Looking forward to the game!

I've been thinking about the CptnRuby code recently, is there anything that you wish was better or more complete about it?
Topic Problem installing Gosu in Ruby 2.3 By jlnr Date 2016-04-27 23:05
Oops, my fault, thanks for reporting this. Please try again.
Topic Mouse issue with Linux By jlnr Date 2016-04-25 07:42
Hey bestguigui, good and bad news if you are still waiting for a fix here.

Ubuntu 16.04 ships with SDL 2.0.4. But only on Linux, the new SDL_GetGlobalMouseState is (practically) broken. SDL 2.0.5 will fix this, but since 2.0.3->2.0.4 took over a year, I'm not holding my breath.

So what I did is try to improve the mouse logic so that your mousing code works on all versions of Linux. The only limitation is that I still cannot update mouse_x and mouse_y while the mouse is outside the window.

In any case, the hack I've suggested above is not necessary anymore.
Topic Gosu 0.10.7 released By jlnr Date 2016-04-25 07:39
Also, I've made sure that everything works on the new and shiny Ubuntu 16.04.
Topic Gosu 0.10.7 released By jlnr Date 2016-04-25 07:36
A grab bag of fixes and updates:

• Windows: Support for Ruby 2.3.0
• Linux: Improve mouse getters/setters
• Ruby: Fix Gosu::random not being random
• All: Update stb_image, stb_image_write, stb_vorbis
• Mac: Reduce Gosu::Font artefacts
• Ruby: Fix compilation issues with Ruby 1.9.3

This is the first release of Gosu that uses both Travis CI and AppVeyor to ensure that things work as expected. Yay, green badges at the bottom! Cross-platform refactoring was a pain before this.

Also, the RubyMotion/iOS version works really well! I hope I can finish my game soon and document how to port stuff to iOS :)
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-04-18 18:45

> My post contains two lists. Which one needs libsndfile?

To be honest, I'm not even sure. It seems that only Gosu itself should need it. Sometimes linking a game requires a dependency .lib though, and I haven't taken the time to work out why. I usually go with trial & error, like a pro. :/ So, if everything builds and sound works, then don't worry.

> What if we made a "Getting Started on Windows" page that linked to separate MSVC and Mingw pages?

Sounds good! Can you create new wiki pages as a non-org member? If not, I can simply make you a member.

One thing that worries me a little is the amount of Linux distros, Ruby versions, C++ compilers etc. Gosu is built with. But I've already opened a gazillion tabs in the background to sign up for free CI services. It seems like this will be an evening well spent. If I understand things right, Appveyor even lets you automate MinGW builds (for free!), which would make me feel much better about having a MinGW Makefile in Gosu's git repository proper. But first I'll set up Travis for Linux builds.
Topic "undefined method 'draw' for nil:NilClass (NoMethodError)" ? By jlnr Date 2016-04-16 07:20
Ha, I hadn't even seen this tutorial before. Nice :) I've gotten to the point where the player is first shown on the screen. There are two issues with this Tutorial that can lead to errors.
At one point in the example code, @sprite is mis-spelled as @spirte, and this would cause a NoMethodError, because @spirte is not assigned and instance variables (starting with @) are nil by default. The other issue is that the order in which things have to be called is important. GameWindow#initialize has to set $window to point to itself BEFORE creating the SceneMap`.

This is the code that I have so far, all in one file for simpler pasting:

And by the way, there's no reason to use Ruby 1.9.3 with Gosu anymore. Ruby 1.8 through 2.2 are all supported, only 2.3 is missing right now :)
Topic One Hit KO By jlnr Date 2016-04-08 08:30
That looks like it feels really good to play, if that makes sense. Does everything in this video already work, or is some of it just added for show? It looks like it wouldn't need much more work to be playable :)
Topic What's wrong with this music? By jlnr Date 2016-04-04 11:58
You mean, it is also broken? Okay, that is good insofar as stb_vorbis is probably not the problem.

I wonder if Gosu stubbornly assumes 22 kHz audio, but your file is 48 kHz or so? Can you try to export it with a lower kHz frequency? I don't have Audacity handy right now.
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-04-04 09:37
1. The DirectX SDK used to be required up until Gosu 0.8.0. Now this is all handled by SDL2.lib, which wraps this for us.

delayimp.lib is MSVC-specific and does not really matter.

2. I'm curious about glu32, does it break if you omit this library? Gosu doesn't really use it.

I think you forgot libsndfile in your list, but otherwise it looks fine.

> It would be great if there was an up-to-date (per platform?) list of every library needed for both Gosu itself and Gosu apps. Something to add to the wiki, maybe?

I think the list of dev dependencies can live on the Wiki page for the respective platform, as with GettingStartedOnLinux. If you compile Gosu with MSVC, gosu.git includes all the required .lib files (SDL2, OpenAL, libsndfile), so this only applies to Compiling-in-Windows-using-MinGW. (Which should probably be renamed to be more in line with the other GettingStartedOn... pages)

Not sure where to list the runtime dependencies. Does the MSYS/MinGW build need libraries at runtime that the MSVC build doesn't? Are pthread and stdc++ statically linked?
Topic What's wrong with this music? By jlnr Date 2016-04-04 08:57
Hrm, this might be related to Gosu switching to stb_vorbis instead of libogg/libvorbis in Gosu 0.10.x. I'll open a GitHub issue. Does the WAV version sound right?

Topic Gosu's Font error By jlnr Date 2016-04-04 08:55
The easiest way is to use "gem uninstall gosu" to uninstall your current version, then "gem install gosu -v 0.9.2" to install the old version instead. To reinstall the latest version, you can simply run "gem update gosu" later.
Topic Gosu's Font error By jlnr Date 2016-04-01 22:57
Can you please retry with Gosu 0.9.2 and see if it works? The only difference is that you'll have to explicitly call super(640, 480, false) in initialize. I wonder if it has to do with the new compiler I'm using for Gosu 0.10.x.

I have noticed that some builds of Ruby itself are not compatible with Windows XP anymore. I don't think Ruby 1.9.3 should be affected, though.
Topic hotswapping code with pry By jlnr Date 2016-04-01 22:53
It sounds as if you should avoid calling in your .rb file, and instead you should find a way to patch the currently running window. I don't have much experience with pry, though.

I've recently used flgr's "again" gem for live code reloading and it worked quite well:

This is the git repo - it says it's a RubyMotion game, but it also works in plain Ruby:

(Now if I could only find the time to finish the actual game...)
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-27 21:39
Awesome, congrats on the working build :)
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-27 18:29
I remembered that it is "/subsystem:console" in the Visual C++ compiler, and that brought up this result:
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-24 19:45
Sweet! :) Thanks for digging into this. I think putting the whole Makefile into the wiki wouldn't be such a bad idea - it makes it even easier to contribute to it.
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-20 15:17

> Does that also mean I don't need the three Ogg/Vorbis .DLLs when I distribute my games?

Yep! Gosu still needs libsndfile.dll, though.
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-20 00:02
Ah right, the MinGW Makefile precedes the switch from libogg/libvorbis to stb_vorbis.c. We should probably fix this in master too.

The only thing I found about the pthread error is this:

But I'm not sure how that translates to your setup.
Topic Getting (& Keeping) libgosu & C++ Games Compiling in MSYS2 By jlnr Date 2016-03-19 19:58
Is it maybe as simple as passing -lstdc++ to the linker? It looks like it can't find anything from the standard library :)

If C++11 is a problem, you can retry with the last C++98 version of Tutorial.cpp:
Topic Gosu and video settings By jlnr Date 2016-03-16 23:14
Welcome, glad you're enjoying Gosu!

Both options should perform exactly the same in terms of speed, but 2) will use less video memory. Thanks to bestguigui for the explanation :)

The rule of thumb with Ruby/Gosu is that the bottleneck is usually Ruby itself, not the rendering in OpenGL/Gosu. If you add lots of code to handle scaling factors based on the user's display quality settings, you might end up making the game slower for everyone because of all the calculations that happen in Ruby. AI and collision detection, for example, are easily more expensive than rendering in a typical Ruby/Gosu game.
Topic Image scaling problem? (FULLSCREEN) By jlnr Date 2016-02-26 15:33
0.10.6 is out and hopefully addresses this bug.
Topic Gosu 0.10.6 released By jlnr Date 2016-02-26 15:32
This is a tiny hotfix update for the Windows fullscreen bug reported here:
Topic Mouse issue with Linux By jlnr Date 2016-02-24 21:20
Also, I'm not sure if I remember the issue correctly, but I think you cannot set both mouse_x and mouse_y in the same tick before SDL 2.0.4, right? Wouldn't it work well enough if you set mouse_x in every even frame, and mouse_y in every odd frame? Or you only reset the value which has moved the furthest from the screen centre? Ugly hacks and gamedev go hand in hand ;)
Topic Image scaling problem? (FULLSCREEN) By jlnr Date 2016-02-22 16:45
Sorry for the delay, I've tested it on Windows and you are right. I can also confirm that it has already been broken in Gosu 0.10.4. Everything works as expected on OS X.

I've filed a ticket here:

I hope this high priority bug gives me an excuse to spend a couple of evenings on Gosu. In the meantime, I'm sorry for this blatant error!
Topic Animate image after key press By jlnr Date 2016-02-22 16:20
Yep, exactly. A few minor nitpicks:
- You don't any of these semicolons in Ruby :)
- In draw, you want to iterate over the boxes and .draw each of them. You can use a for ... in loop for that, but @box.each { |b| b.draw } is more common in Ruby. It can even be shortened to @box.each(&:draw).
- Method names usually use_underscores() instead of javaCase()
- You don't need to pass false to super in initialize anymore, that's Gosu's old interface (which still works). The new way is super(w, h) or super(w, h, fullscreen: some_boolean)
- In button_down, you can use button_id_to_char to see which number was pressed:
  def button_down(id)
    ch = Gosu::button_id_to_char(id)
    if ch =~ /^[0-9]$/ then # Regexp to test for 0-9
      index = (ch.to_i + 1) % 10
      box[index].move = true

That has the advantage of also working with the numpad.

Also, sorry for the troublesome forum markup! I really wish it was Markdown.
Topic Using KbUp and KbDown in a TextInput on a Mac By jlnr Date 2016-02-22 08:09
Nooooooo, don't break my up/down keys on OS X!! ;)

I think we could add an callback like filter() except that it is called for arrow/modifier combinations? Feel free to fork gosu and give it a try. Compiling Gosu is as easy as:

cd my-gosu-fork
export GOSU_RELEASE_VERSION=0.99.0 # whatever
rake gem
gem install pkg/gosu-0.99.0.gem

Hope that helps!
Topic Mouse issue with Linux By jlnr Date 2016-02-21 13:24
It always depends on the Linux distribution, but for Ubuntu, SDL 2.0.4 will be available in the 16.04 update. So at least there is a solution on the horizon... :)

And you can always manually install SDL 2.0.4 from source, by using the ./configure && make && sudo make install dance, but I have never done that on Ubuntu and I don't know if Gosu would pick up the custom SDL installation by default.
Topic Image scaling problem? (FULLSCREEN) By jlnr Date 2016-02-20 23:51
That's really curious. I wonder if it has anything to do with your DPI settings? Are you running Windows 7 at 100%, 125% or 150% font scale? (It's somewhere in the display settings.)

I'll give it a try on my Windows 7 VM ASAP.
Topic Capture window to image? By jlnr Date 2016-02-20 23:49
2D graphics operations are outside of Gosu's scope. Implementing Window#to_image would be much easier than replicating all of Gosu's drawing operations in software :)

I've opened a ticket:

...but progress is suuuper sloooow right now. =/

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill