Hi to all!
I'm new here on forum, and just newbie with Gosu (about 2 months). And I'm from Russia and don't realy often use english, so don't blame me to hard for possible mistakes))
So...
I'm in construction of my own engine. I'm using Gosu, Rmagick, Inifile, Chipmunk and Chingu (two lasts I'm not really use by now, maybe later). And in produsing my engine I thought about (IMHO) usefull features? that could be implemented in Gosu, because I use them every time, but don't see them in Gosu...
They are:
1. Method (and also a class) for cursor. By now I'm using somewhat similar to this:
class GameCursor
attr_accessor :image
def initialize filename = nil
case filename
when nil; Gosu::Window.class_eval {def needs_cursor?; false; end}
when ""; Gosu::Window.class_eval {def needs_cursor?; true; end}
when String
Gosu::Window.class_eval {def needs_cursor?; false; end}
@image = Gosu::Image.new(filename)
end
end
def draw x, y; @image.draw(x, y, 100000); end
end
#and in my main class:
class MyClass < Gosu::Window
def initialize #...
#...
@cursor = GameCursor.new (#...)
#...
end
#....
def draw
@cursor.draw
#...
end
end
This is not all, that I do with my cursor object (not only implement custom image for it))), but these are basics, that I thought, should be in Gosu core... (Rubygame has this)
2. Is there any way to draw Magick::Image instead of Gosu::Image? I'm on Windows7, so method #display doesn't fit to me))
3. I'm in need to know screen resolution of user, that will be play my games. For now I'm using Tk methods such are:
require 'tk'
$screen_width = TkWinfo.screenwidth(Tk.root)
$screen_height = TkWinfo.screenheight(Tk.root)
#and so on... aspect ratio, scale factros, restricted on screew width, that user sets in ini-file...
In last update you began integration with Tk, so I thought, that maybe some of this features could be implemented in gosu core?
That is not all, but for the first time it's ok. I would be grateful for an answer!
By jlnr (dev)
Date 2015-09-15 21:57
Hi and welcome :)
1. Instead of rewriting methods on Gosu::Window
with class_eval
, you can just add a setter to your own Window subclass:
class MyWindow < Gosu::Window
...
attr_accessor :cursor
def initialize(...)
...
# Neither default cursor, nor a custom cursor image - I think this makes for nicer code than ""
@cursor = false
end
def needs_cursor?
@cursor.nil?
end
def draw
...
if @cursor then
# This is a bit of a hack - it's probably better to cache cursors indefinitely in a Hash
@cursor_image ||= Gosu::Image.new(@cursor)
@cursor_image.draw mouse_x, mouse_y, 1000000
end
end
end
2. No, Magick::Image
is a bitmap in memory, Gosu::Image
is an OpenGL texture, or something similar. But you can convert RMagick images to Gosu using Gosu::Image.new(rmagick_image)
.
(And I feel I have to point out that releasing games that depend on RMagick is going to be complicated =/ Deploying Texplay is a lot easier.)
3. Gosu::screen_width
and Gosu::screen_height
are your friend.
Thanks for the feedback! I'll try to look at the asynchronous image loading soon-ish, as well.
By Salazar
Date 2015-09-16 08:39
Edited 2015-09-16 08:47
Thanks for answer!
I use only RMagick, because TexPlay doesn't work with Ruby 2.2. And, Rmagick, obviously more functional.
By jlnr (dev)
Date 2015-09-16 09:30
Oh, I didn't know that about TexPlay. =/
Loading...