Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
1 2 3 4 5 6 Previous Next  
Search
Topic Window problemes [ruby] By erisdiscord Date 2011-11-24 20:24
Well, my impression is that system(…) works on Windows as do threads, which is why I assume Jwosty's answer would work there, but I could be mistaken. C:

I freely admit that I haven't used Windows in earnest since 2005, possibly even longer. That's when I got my first Mac, but I know I used Linux a lot off and on before then, so I dunno. I'm out of the loop!
Topic Window problemes [ruby] By erisdiscord Date 2011-11-24 20:11
Fork doesn't work on Windows? How do you run a child process without waiting for it to return?

Oh, derp, Jwosty's solution would work on Windows wouldn't it.
Topic Window problemes [ruby] By erisdiscord Date 2011-11-24 16:51
Whoops, you beat me to it.  I wrote up my post a while ago and then forgot to post!
Topic Window problemes [ruby] By erisdiscord Date 2011-11-24 16:51
Yeah, system waits for the program being called to finish, so your program is hanging there because it's waiting for espeak. If you want to let espeak run in the background and not wait for it to finish, there are a couple of ways to do it, but here's one:

# create a new child process
pid = fork do
  # call espeak. exec never returns, so the child process effectively ends here.
  exec('espeak', 'bonjour')
end

# detach the child process; we aren't interested in waiting for it.
Process.detach pid


There is also an espeak gem. It looks like it can only record to a file, but you could create a temporary file and then load it as a Gosu::Sample. That's probably too much if you're just starting out, though. The solution above is far easier. :Ɔ
Topic Gosu 0.7.40 released By erisdiscord Date 2011-11-20 09:16
Perhaps it's time to refactor slightly: new base class (Drawable) that is inherited by Image and Macro. That way there's no worrying whether an image is actually an image, right? C:

At least once all the draw methods work for recorded macros.
Topic Gosu 0.7.39 released By erisdiscord Date 2011-11-19 05:34
Goodness. Record is working? I'm gonna have to dig out some of my old code one of these days and try it out. :D
Topic Incorrectly handled image alpha channel By erisdiscord Date 2011-11-10 15:04
See what I mean about Linux distributions dragging their asses? I barely expect Ruby 1.9 to become the standard version across distributions by 2013. C:
Topic Transparent pixels causes darkening? By erisdiscord Date 2011-10-23 19:41
As a sort of workaround, you might export the glow and the icon as separate tiles, then draw the icon normally and draw the glow additively.
Topic Gosu, Ubuntu and Ruby By erisdiscord Date 2011-10-21 04:48
It kind of seems like Ruby 1.9 has been pretty horribly broken on Ubuntu in the past, but I can't back that up. I know I've had some major headaches with it.

I wish these Linux distributions would just distribute vanilla binaries instead of dicking around and applying a bunch of their own patches to everything. We might get updated packages in a more timely manner if they'd just leave well enough alone. Still kinda sore that Ubuntu thinks Ruby 1.8 is the best choice for "default version" when 1.9 has been stable for over two years.
Topic No Place Like Homeless (UPDATED 6.22.2014) By erisdiscord Date 2011-10-19 14:52

> The other option is to give it away on PC and sell it on iOS.


Works on people like me. I bought the iOS version of Horror Vacui because I liked the free Wii homebrew version. :D
Topic Set image transparency By erisdiscord Date 2011-10-10 23:08
This is a good change. :D
Topic draw_line y coordinate off by one? By erisdiscord Date 2011-10-06 04:01
+1 This is what I was trying to suggest, but expressed more clearly. C:
Topic draw_line y coordinate off by one? By erisdiscord Date 2011-10-06 01:23
It's an unfortunate OpenGL bug, or implementation detail, or something. I think Julian has mentioned before that OpenGL doesn't really have a good, consistent way to draw a line onscreen. On some platforms, the lines will be drawn in exactly the right place; on others, they will be off by one in either direction. If you can use pre-made images of lines instead, you'll be better off. :C
Topic Problema con la documentacion de gosu! By erisdiscord Date 2011-10-04 01:05
Off topic: Google Translate says "there are hadly two Spanish around here". Is that correct, and is that actually idiomatic Spanish? Because I like the sound of "hardly two" instead of "hardly any". :D
Topic Set image transparency By erisdiscord Date 2011-09-30 03:31
Oops! Wow, that didn't happen for me even after many, many iterations. I had numerous previous versions that did. :D

@jlnr Can we get a constructor that takes normalized floats? I'm much more comfortable with those. C:
Topic Set image transparency By erisdiscord Date 2011-09-29 04:32
Hopefully the jocular nature of my comment came through! I have done it that way and probably would again. :D
Topic Set image transparency By erisdiscord Date 2011-09-27 20:36
More usefully:


  def draw
    …
    if @menu
      alpha = (128 + 128 * Math.sin(Math::PI * Gosu.milliseconds / 1000.0)).floor
      @immagini_logo.draw 0, 0, 0, 1, 1, Gosu::Color.argb(alpha, 255, 255, 255)
    end
    …
  end
Topic Set image transparency By erisdiscord Date 2011-09-27 20:20
Well, for variables that need to be shared across methods, use an instance variable. They shouldn't need to be accessible outside of your object.

As for fading in and out, let me see if I can get the math right this time. I wrote an equation that was wrong and kept getting the corrections wrong a while ago because I was on a tablet and couldn't test it!

There we go. 0.5 + Math.sin(Math::PI * Gosu.milliseconds / 1000.0) / 2 should give you a float in the range 0 – 1 inclusive, with a period of one second. If you want toit to go faster or slower, change 1000 to something else—it's basically the period in milliseconds.
Topic Set image transparency By erisdiscord Date 2011-09-27 15:46
It's also worth a note that you probably shouldn't be using the $ sigil (as in $n), because that indicates a global variable. Just use a bare name for local variables.

You will encounter strange bugs later using global variables like that if you use the same name in more than one place. C:
Topic Set image transparency By erisdiscord Date 2011-09-27 15:41
-1 for being the sort of hack I'd resort to. :D
Topic Gosu 0.7.36(.2) released By erisdiscord Date 2011-08-28 19:21
Well, if you really want to~ :D
Topic Gosu 0.7.36(.2) released By erisdiscord Date 2011-08-28 19:19
They are viewable in QuickLook, but the preview generator has a tendency to crash on my machine. As cool as that hack sounds, I'm not sure it's worth the trouble!
Topic Gosu 0.7.36(.2) released By erisdiscord Date 2011-08-28 15:01
It's a shame I use Pixelmator (can't afford Photoshop) cause this PSD loading feature sounds awesome for prototyping graphics. :D

I guess I could try saving as PSD, but I think Pixelmator's PSD support is kinda lacking.
Topic Gosu 0.7.35 released By erisdiscord Date 2011-08-19 21:42
Nope. The SWIG macro is there as a way to tell SWIG to ignore certain parts of the C++ headers that shouldn't be included in the Ruby bindings.

The warning is complaining about the placement of an attribute on a forward declaration. Strangely, the contents of Gosu/Fwd.hpp specify nothing of the sort.

//! \file Fwd.hpp
//! Contains declarations of all of Gosu's available classes.

#ifndef GOSU_FWD_HPP
#define GOSU_FWD_HPP

//! The library's main namespace.
namespace Gosu
{
    class Audio; // <- this is line 10
    class Bitmap;
    class Buffer;
    class Button;

...
Topic Gosu 0.7.35 released By erisdiscord Date 2011-08-12 15:19
Huh, I hadn't even thought of the implications of ARC for MacRuby. I like ARC because it's less invasive than garbage collection, but it would be hard to retrofit that into Ruby while maintaining C extension compatibility, which seems to be a goal of the project. It doesn't seem like the garbage collector is going away, though.
Topic Gosu 0.7.35 released By erisdiscord Date 2011-08-12 03:30
Speaking of Gosu.app—does Gosu work with MacRuby yet, or do you know? It would make things easier if we could just create a MacRuby application with Xcode.

(For that matter, a Cocoa version of Gosu would be wonderful, but I'm not holding my breath :D)
Topic Windows executable By erisdiscord Date 2011-08-10 01:39
Well~ Maybe not esoteric to the likes of you or me, but certainly to many people it would be so. :D
Topic Windows executable By erisdiscord Date 2011-08-09 20:21
Oh my, that's probably the most fascinatingly esoteric solution yet. I would imagine ReactOS is about as compatible as Wine—they share some code IIRC?
Topic Windows executable By erisdiscord Date 2011-08-09 18:25
I suppose you could create a Windows executable with an embedded Ruby interpreter, if you were willing to go down the cross-mingw32 route. Ruby's easy enough to work with from C, although it still involves working with C and you'd still have to distribute your Ruby source code too—so maybe not such a great idea.

You could always ask someone else to do it for you, I guess!
Topic Windows executable By erisdiscord Date 2011-08-09 15:18
I don't know if there are any easy answers here. If you're using Ruby Gosu, probably not; if you're using C++ Gosu, there's the option of compiling a mingw32 cross-compiler, but that's pretty time consuming and, as it turns out, a tremendous pain.

There are numerous options (Boot Camp, VMware, Parallels, Virtual Box) for running Windows on your Mac, although you'd still need to get your hands on a copy of Windows. This is probably the easiest way.
Topic About 'data' By erisdiscord Date 2011-07-31 04:25
There's also YAML, which is both easier and more concise than XML and much more powerful than JSON, if you need it to be. Some people find its significant indentation (like Python or CoffeeScript) infuriating, but YMMV. I find the indented block syntax to be extremely readable.

All objects in YAML are represented as either maps, lists or scalars, but they can be tagged to tell the deserialiser what kind of object they should become. This might seem like overkill, but it's extremely useful if you want to dump objects from one language and load them in another. Provided that your YAML library supports custom tags, I mean. The one for Ruby does, but I know some implementations are kind of half-assed.

A bonus feature of YAML is that, as of 1.2, all valid JSON is also valid YAML. This is a one-way relationship and most YAML is probably not valid JSON. :)
Topic Compiling Gosu 2D with MinGw on Windows By erisdiscord Date 2011-06-17 21:00
Haha, oops. I kinda missed the compatibility table there. Mistakes happen!
Topic Compiling Gosu 2D with MinGw on Windows By erisdiscord Date 2011-06-17 20:21
I'm not an expert on Windows, but shouldn't you be using the non-deprecated, non-superseded SHGetKnownFolderPath instead?
Topic Ruby bindings for Chipmunk 5.3.4 By erisdiscord Date 2011-06-08 14:56
Oh, I didn't know it was new to the Ruby API. I think it was in chipmunk-ffi already?

I think I recall that chipmunk-ffi allows arbitrary objects for collision_type, which is potentially useful because you could have a set of standard collision_type objects that determine additional collision behavior. On the C side, the collision type is just set to the object's id. Doing the same for group might be useful in some cases, so why not make it possible?
Topic Ruby bindings for Chipmunk 5.3.4 By erisdiscord Date 2011-06-08 03:37
I can't answer most of your questions with any authority, but I'd like to weigh in on one thing.

> I wasn't sure why #group wasn't also implemented as a symbol


From the Chipmunk docs:

> group: Shapes in the same non-zero group do not generate collisions. Useful when creating an object out of many shapes that you don't want to self collide. Defaults to 0;


The special treatment of 0 here would mean that the Ruby wrapper would need to do some behind-the-scenes conversion. Assuming you want nil to be the "normal" group, you'd either have to make 0 and nil both set the internal value to 0 (strange and unexpected behavior for Ruby, and lossy) or risk breaking compatibility with existing programs (0 might be set explicitly). I would lean towards the second as more-correct behavior, but~
Topic Gosu 0.7.32 released By erisdiscord Date 2011-06-05 01:59
• Hopefully replaced the last remaining Google Code wiki links with appropriate GitHub wiki links. :)
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-31 14:05
That does it. I am adding this to my bitmap font class.

Extremely simple git patch for the file I posted above:

diff --git a/bitmap_font.rb b/bitmap_font.rb
index 9a11368..08b9370 100644
--- a/bitmap_font.rb
+++ b/bitmap_font.rb
@@ -49,7 +49,12 @@ class BitmapFont
     @window.scale factor_x, factor_y, x, y do
       string.each_char do |ch|
         image = char_image(ch)
-        image.draw x + x_off, y, z, @scale, @scale, color, mode if image
+       
+        if block_given?
+          yield image, x + x_off, y
+        else
+          image.draw x + x_off, y, z, @scale, @scale, color, mode if image
+        end
        
         x_off += char_width(ch)
       end
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-27 15:10
That actually sounds pretty good! I think leaving the specifics of loading non-standard fonts up to us is probably best since, for instance, my BitmapFont wouldn't be suitable for people who need unicode support.

It would be most useful if paired with a constructor that creates an empty font, of course. Gosu::Font.new(window, height)?
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-27 00:31
Well, there might be something wrong with using mine (needs more error checks, could be faster) but... :)

Hey, since Gosu's apparently generating bitmap fonts from truetype fonts anyway, would it be possible to add support for loading characters from a sprite sheet like this? :)
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-25 19:26
As for custom bitmap font classes, here's the one I wrote. It should be more-or-less usable as a drop-in replacement for Gosu::Font, although it doesn't hook into Gosu::Image.from_text. Instead, I've added a render method that accepts the same arguments. The render method requires TexPlay, but everything else should work with just Gosu.

Beware that rendering to an image is slow, so you'll probably want to do it at some kind of loading screen rather than on the fly. I'm not sure how to solve that since TexPlay doesn't natively support splice-and-scale as far as I know. The way I've done it is a dirty hack. :)

As for licensing, consider it under the same license as Gosu.

require 'gosu'
require 'json'
require 'weakref'

class BitmapFont
 
  WORD_BREAK     = /\s|\b-|$/
  CHARSET_RANGE  = 0x20..0x7f
 
  def initialize window, filename, height = nil
    properties = File.open(filename) { |io| JSON.load io }
   
    # probably shouldn't hold onto this, but...
    @window = WeakRef.new window
   
    @name = properties['name'] || File.basename(filename).sub(/\.[^\.]+$/, '')
   
    # font metrics
    @width  = Integer properties['width']
    @height = Integer properties['height'] || @width
    @scale  = height ? height.to_f / @height : 1
   
    @exceptions = properties['exceptions'] || { }
   
    # images
    image_filename = if properties.include? 'image'
      File.expand_path properties['image'], File.dirname(filename)
    else
      filename.sub /\.[^\.]+$/, '.png'
    end
   
    tile_width  = properties['tile_width']  || @width
    tile_height = properties['tile_height'] || @height
   
    @images = *Gosu::Image.load_tiles(window,
      image_filename, tile_width, tile_height, false)
  end # initialize
 
  def height
    @height * @scale
  end
 
  def text_width text, factor_x = 1
    text.each_char.inject(0) { |width, ch| width + char_width(ch) } * factor_x
  end
 
  def draw string, x, y, z, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default
    x_off = 0
    @window.scale factor_x, factor_y, x, y do
      string.each_char do |ch|
        image = char_image(ch)
        image.draw x + x_off, y, z, @scale, @scale, color, mode if image
       
        x_off += char_width(ch)
      end
    end
  end # draw
 
  def draw_rel text, x, y, z, rel_x, rel_y, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default
    draw_width  = text_width(text, factor_x)
    draw_height = height * factor_y
    @window.translate(-draw_width * rel_x, -draw_height * rel_y) do
      draw text, x, y, z, factor_x, factor_y, color, mode
    end
  end
 
  def draw_rot text, x, y, z, angle, factor_x = 1, factor_y = 1, color = 0xffffffff, mode = :default
    @window.translate(x, y) do
      @window.rotate(angle) do
        draw_rel text, 0, 0, z, 0.5, 0.5, factor_x, factor_y, color, mode
      end
    end
  end
 
  def render text, line_spacing, max_width, align
    raise NotImplementedError,
      "Rendering to an image requires TexPlay to be installed", caller \
      unless defined? ::TexPlay
   
    lines = word_wrap(text, max_width)
   
    draw_width  = max_width
    draw_height = (height + line_spacing).floor * lines.count
   
    canvas = TexPlay.create_image @window.__getobj__, draw_width, draw_height,
      :caching => false
   
    y_off = 0
    lines.each do |line|
      render_line canvas, line, y_off, align
      y_off += (height + line_spacing).floor
    end
   
    canvas
  end # render
 
  private
 
  def parse_characters spec
    case spec
    when Enumerable
      spec.inject([]) { |charset, subspec|
        charset += parse_characters(subspec) }
    when /^(.)-(.)$/
      ($1..$2).to_a
    else
      spec.characters
    end
  end
 
  def char_image ch
    if CHARSET_RANGE.include? ch.ord
      index = ch.ord - CHARSET_RANGE.begin
      @images[index]
    end
  end
 
  def char_width ch
    if @exceptions.include? ch
      @exceptions[ch] * @scale
    else
      @width * @scale
    end
  end # char_width
 
  def word_wrap text, max_width
    lines = [ ]
   
    first_index = 0
    last_index  = test_index = text.index(WORD_BREAK)
   
    while test_index
      if text_width(text[first_index ... test_index]) >= max_width
        lines << text[first_index ... last_index]
        first_index = last_index + 1
      end
     
      last_index = test_index
      test_index = text.index WORD_BREAK, last_index + 1
    end
   
    lines << text[first_index .. last_index]
    lines
  end # word_wrap
 
  def render_line canvas, line, y_off, align
    x_off = case align
            when :left   then  0
            when :center then (canvas.width - text_width(line)) / 2
            when :right  then  canvas.width - text_width(line)
            end
   
    line.each_char do |ch|
      image       = char_image(ch)
      draw_width  = char_width(ch)
      draw_height = height.floor
     
      canvas.rect x_off, y_off, x_off + draw_width, y_off + draw_height,
        :color => :white,
        :fill  => true,
        :color_control => proc { |src, dst, x, y|
          image.get_pixel(((x - x_off) / @scale).floor,
                          ((y - y_off) / @scale).floor) || src || :none }
     
      x_off += draw_width
    end
  end # render_line
 
end # BitmapFont

begin
  require 'texplay'
rescue LoadError
  $stderr.puts('TexPlay is not available; BitmapFont rendering will be ' +
               'unavailable') if $DEBUG
end
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-25 19:15
I actually found mine a while ago, so I added support for rendering to an image for the hell of it. I'm about to post it. :)
Topic Disabling antialiasing for Gosu::Font By erisdiscord Date 2011-05-25 13:29
No way that I know of. I'm pretty sure Gosu uses different text renderers depending on the platform, anyway, so some renderers may not even support it.

If you aren't dealing with dynamic text, you might be better off using static images anyway. It's faster and guaranteed to be consistent across platforms (well, as consistent as any other image drawing) at the cost of increased distribution size.

On the other hand, if you're using a lot of dynamic text, implementing a simple bitmap font class isn't too difficult and you can add features that Gosu::Font doesn't support, like word wrapping. I've got such a class lying around somewhere, if I can find it.
Topic About "translate(x, y, &drawing_code)" & about fullscreen... By erisdiscord Date 2011-05-22 14:47
To clarify what Dahrkael is saying, you call translate, rotate and scale with a block , which is a common pattern in Ruby. If you don't know about blocks, you might want to Google for more information.

The "drawing code" that goes there is just standard Gosu calls, like @image.draw(x, y, z). These transformations are applied to everything that's drawn inside of the block.

For example, using translate, one might replace code like this:

@player.draw @player_x - @scroll_x, @player_y - @scroll_y
@enemy.draw  @enemy_x  - @scroll_x, @enemy_y  - @scroll_y
...


with code like this:

translate(-@scroll_x, -@scroll_y) do
  @player.draw @player_x, @player_y, 0
  @enemy.draw  @enemy_x,  @enemy_y,  0
  ...
end


Which is, in my opinion, more readable. In practice, you'd probably want to use a more object oriented approach, but I figured it would be more clear what I was talking about this way. If you've got any further questions, don't be shy.
Topic About "translate(x, y, &drawing_code)" & about fullscreen... By erisdiscord Date 2011-05-22 14:28
You can pass a proc anywhere there's a block, but you have to prefix it with &. These two are roughly equivalent, although I suspect the second one is not so efficient:

translate(x, y) do
    @player.draw
end


draw_proc = proc { @player.draw }
translate(x, y, &draw_proc)


The cool thing about this is that you can pass Method objects as blocks this way too.
Topic Can’t compile under linux. LibX11 error … By erisdiscord Date 2011-05-20 22:04
I feel CMake is not that great either. The Xcode projects it creates are structured oddly and it's nearly impossible to trace the source of a library error in its Makefile output. I've always had terrible luck with it. :C

I'd like to see something akin to Ant, but without all the verbosity of XML. Build systems that just generate files for other build systems are lame.
Topic Errors error By erisdiscord Date 2011-05-01 01:32
For what it's worth, you can also stick a rescue clause directly at the end of a method, module or class definition, saving a level of nesting.

def update
  update_callback
rescue SystemExit
  close
rescue Exception => e
  puts e.message
  puts e.backtrace
  close
end

def draw
  draw_callback
rescue SystemExit
  close
rescue Exception => e
  puts e.message
  puts e.backtrace
  close
end
Topic Gosu 0.7.30 released By erisdiscord Date 2011-04-30 05:08
I'll try to do something with MacRuby tomorrow. For now, I'll be having happy dreams about it I'm sure. :D

Oh right, tomorrow's my girlfriend's birthday party. Scratch that, I'm gonna have cake and ice cream. I'll try to do something with MacRuby later this week. :)
Topic Gosu 0.7.30 released By erisdiscord Date 2011-04-30 04:26
Ooh, one step closer to switching to MacRuby as my primary Ruby. I'm really liking these Ruby implementations on top of other runtimes (MacRuby, JRuby, IronRuby, &c.) as of late.
Topic __NSAutoreleaseNoPool(): ... autoreleased ...- just leaking By erisdiscord Date 2011-04-16 22:49
Call them "modes" if you want; I don't see where delegating calls to different objects for different modes of operation is a hack any more than closing one window and opening another is, especially since Gosu's Window is really meant to be instantiated once and only once. Most of your code would not need to change—just create one new class that your "windows" inherit from (not strictly necessary), one Window subclass that just does the delegation, then make sure that you pass your single window instance to any image or sample constructors.

I don't see anything immediately obvious that should be causing leaked autoreleases, but from my observations I'm gonna say it's probably caused by your use of multiple windows. It's also worth noting that the additional windows stay open behind, so at the game over screen you've got the menu and the game window hanging out behind it. It seems like there are probably multiple Cocoa run loops going at this point and I'm pretty sure run loops other than the main don't have autorelease pools unless you explicitly allocate them.
Topic __NSAutoreleaseNoPool(): ... autoreleased ...- just leaking By erisdiscord Date 2011-04-16 04:30
Huh, I know exactly what causes it in the general case, but I've never seen it with Gosu. Are you using any Cocoa APIs directly?

You tend to see this a lot with SDL games when they interact with the window server (setting the window title, querying window geometry) because Cocoa makes extensive use of autorelease and SDL is sloppy and doesn't set up autorelease pools around native operating system functions, but Gosu uses Cocoa's native application run-loop so autorelease pools are allocated automatically. That makes this error kinda mysterious.

I notice you seem to be using multiple Window classes. I don't think this is really supported and it could be the indirect source of your NSAutoreleasePool woes. Do you see this warning when the first window (MenuWindow from the looks of it) is open before you start a game?

And finally: I recommend you look into the state pattern—instead of having multiple Window classes, have a single Window object that delegates its draw, update, &c methods to a GameState object and put the code you currently have in your Window subclasses into GameState subclasses instead. When you want to go from menu to game or game to game over, switch out your state instead of your window.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill