Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
1 2 Previous Next  
Search
Topic Gosu::Window#tick doesn't raise error. By Andrek Date 2021-04-26 13:50
Back to working with this, i checked the pull request and use that version instead this because i'm using Ruby 3.

Thanks a lot :)
Topic Gosu::Window#tick doesn't raise error. By Andrek Date 2021-04-24 13:30
Thanks! I'll wait for that, while I have the solution that I said rencently.
Topic Gosu::Window#tick doesn't raise error. By Andrek Date 2021-04-24 13:25
I tested Gosu::Window#tick alone and realized that is its fault and EventMachine has nothing to do here, for now i'm catching errors in Gosu::Window#update by my self using this:

require 'eventmachine'
require 'gosu'

class Window < Gosu::Window
  def initialize
    super(640, 480)
  end
  def update
    begin
      0 / 0 # Generate error.
    rescue => e
      p e
      self.close
      EM.stop
    end
  end
end

$window = Window.new

EM.run do
  EM.add_periodic_timer(1 / 60.0) { $window.tick }
end


Is there a way to check if Gosu::Window is closed? want to:
EM.add_periodic_timer(1 / 60.0) { $window.tick unless $window.closed? }
Topic Gosu::Window#tick doesn't raise error. By Andrek Date 2021-04-22 17:07
I'm working with Event Machine and Gosu so i'm using Gosu::Window#tick to make them work together and everything is fine till a error occurs in Gosu Loop(tick) and doesn't raise it and the Gosu::Window get bugged, i can't debbug my code so i'm stuck!

Sample code:
require 'eventmachine'
require 'gosu'

class Window < Gosu::Window
  def initialize
    super(640, 480)
  end
  def update
    0 / 0 # Generate error.
  end
end

$window = Window.new

EM.run do
  EM.add_periodic_timer(1 / 60.0) { $window.tick }
end


I'm following Using EventMachine with GTK+ and Using EventMachine with Qt
so i think this is the correct way.

Note: EM.add_periodic_timer is not a thread so Gosu::Window#tick can work correctly.
Topic Playing a song with Gosu By Andrek Date 2019-01-22 23:10
Right! 100% working :)
Topic Playing a song with Gosu By Andrek Date 2019-01-19 23:43
Thanks! your code works for me and i happy now, when I update gosu, stopped playing sounds, the error that I mentioned before but after I restart everything is fixed.
Topic Playing a song with Gosu By Andrek Date 2019-01-16 18:53
i upload the mp3 file and update my gosu gem and now i can't play any sound, this does not works:

class MW < Gosu::Window
  def initialize
    super 640, 480
    @song = Gosu::Song.new("alert2.mp3")
    @song.play
  end
end

window = MW.new
window.show


Well, in my project i'm using gosu to load image, no drawing, this is just an IA comparing images and i wanted use Gosu to play a sond when my IA found something, i'm using win32-sound gem(converting my mp3 to wav) now. I used a Thread just like a example because i'm using gosu in the main thread without calling a Gosu::Window of course:

if compare_img(img) == :face
  Gosu::Song.new("alert2.mp3").play
end


Thanks!

Edit: adding @song.play, sorry i forgot it.
Topic Playing a song with Gosu By Andrek Date 2019-01-14 12:32
Is there a way to play a song with Gosu without start the main loop window.show

Something like this:

Thread.new do
  song = Gosu::Song.new("file.mp3")
  song.play
  loop do
    song.update
    break unless song.playing?
  end
end


And why i get this error that works with Gosu::Song:

song = Gosu::Simple.new("file.mp3") # => RuntimeError: File contains data in an unknown format.

Thanks a lot! :)
Attachment: alert2.mp3 (33k)
Topic Problem installing Gosu in Ruby 2.3 By Andrek Date 2016-04-28 03:28
I used: 'gem install gosu' and now work!! thanks you!!!
Topic Problem installing Gosu in Ruby 2.3 By Andrek Date 2016-04-27 14:06
It isn't work :S



I had installed Ruby Installer and DevKit, Gosu run on Ruby 2.3 or i need Ruby 2.2?

I'll try with Ruby 2.2!!

Edit: No work :S
Topic Problem installing Gosu in Ruby 2.3 By Andrek Date 2016-04-26 22:23
Hi! i can't install Gosu in Ruby 2.3

Microsoft Windows [Versión 6.3.9600]
(c) 2013 Microsoft Corporation. Todos los derechos reservados.

C:\Users\Gordon>gem install gosu
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing gosu:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby23/lib/ruby/gems/2.3.0/gems/gosu-0.10.7/ext/gosu
C:/Ruby23/bin/ruby.exe -r ./siteconf20160426-2900-1dlz4st.rb extconf.rb
This gem is not meant to be installed on Windows. Instead, please use:
gem install gosu --platform=i386-mingw32

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby23/lib/ruby/gems/2.3.0/gems/gosu-0.10.
7 for inspection.
Results logged to C:/Ruby23/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/gos
u-0.10.7/gem_make.out

C:\Users\Gordon>


Maybe i need Ruby 2.2?

I'm on Windows 8.1
Topic Gosu's Font error By Andrek Date 2016-04-04 10:25
Thanks you it's work!!!
Topic Gosu's Font error By Andrek Date 2016-04-03 20:35
Ok! but how i can install gosu 0.9.2? thanks you for your reply!
Topic Gosu's Font error By Andrek Date 2016-04-01 01:23
Hi! i can't draw fonts with Windows XP, but i can with Linux Mint 17.3.

Error:
Microsoft Windows XP [Versión 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Ruby193>ruby test.rb
test.rb:9: [BUG] Segmentation fault
ruby 1.9.3p551 (2014-11-13) [i386-mingw32]

-- Control frame information -----------------------------------------------
c:0014 p:---- s:0041 b:0041 l:000040 d:000040 CFUNC  :draw
c:0013 p:0021 s:0034 b:0034 l:000033 d:000033 METHOD test.rb:9
c:0012 p:0031 s:0031 b:0031 l:000cbc d:000030 LAMBDA C:/Ruby193/lib/ruby/gems/1.
9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patches.rb:28
c:0011 p:---- s:0027 b:0027 l:000026 d:000026 FINISH
c:0010 p:0011 s:0025 b:0025 l:000024 d:000024 METHOD C:/Ruby193/lib/ruby/gems/1.
9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patches.rb:38
c:0009 p:---- s:0022 b:0022 l:000021 d:000021 FINISH
c:0008 p:---- s:0020 b:0020 l:000019 d:000019 CFUNC  :tick
c:0007 p:0027 s:0017 b:0017 l:000016 d:000016 METHOD C:/Ruby193/lib/ruby/gems/1.
9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/patches.rb:135
c:0006 p:---- s:0014 b:0014 l:000013 d:000013 FINISH
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 CFUNC  :show
c:0004 p:0011 s:0009 b:0009 l:000008 d:000008 METHOD C:/Ruby193/lib/ruby/gems/1.
9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patches.rb:45
c:0003 p:0051 s:0006 b:0006 l:00233c d:00107c EVAL   test.rb:12
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:00233c d:00233c TOP

-- Ruby level backtrace information ----------------------------------------
test.rb:12:in <main>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patche
s.rb:45:in
show'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patche
s.rb:45:in show'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/patches.rb:
135:in
tick'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/patches.rb:
135:in tick'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patche
s.rb:38:in
protected_draw_2'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_patche
s.rb:28:in block (2 levels) in <class:Window>'
test.rb:9:in
draw'
test.rb:9:in `draw'

-- C level backtrace information -------------------------------------------
C:\WINDOWS\system32\ntdll.dll(KiFastSystemCallRet+0x0) [0x7c91e514]
C:\WINDOWS\system32\kernel32.dll(WaitForSingleObject+0x12) [0x7c802542]
C:\Ruby193\bin\msvcrt-ruby191.dll(rb_vm_bugreport+0xf9) [0x62e7c9d9]
C:\Ruby193\bin\msvcrt-ruby191.dll(rb_name_err_mesg_new+0x186) [0x62d41436]
C:\Ruby193\bin\msvcrt-ruby191.dll(rb_bug+0x2f) [0x62d4229f]
C:\Ruby193\bin\msvcrt-ruby191.dll(rb_check_safe_str+0x1f0) [0x62e04220]
[0x004011e6]
[0x09527d62]
C:\WINDOWS\system32\kernel32.dll(UnhandledExceptionFilter+0x1c7) [0x7c864771]

-- Other runtime information -----------------------------------------------

* Loaded script: test.rb

* Loaded features:

    0 enumerator.so
    1 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/encdb.so
    2 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/iso_8859_1.so
    3 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/transdb.so
    4 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb
    5 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb
    6 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/deprecate.rb
    7 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/exceptions.rb
    8 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/defaults/operating_system.rb
    9 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb
   10 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems.rb
   11 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb
   12 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/requirement.rb
   13 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/platform.rb
   14 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb
   15 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/path_support.rb
   16 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/utf_16le.so
   17 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/utf_16_32.so
   18 C:/Ruby193/lib/ruby/1.9.1/i386-mingw32/enc/trans/single_byte.so
   19 C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/1.9/gosu.s
o
   20 C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/swig_
patches.rb
   21 C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu/patch
es.rb
   22 C:/Ruby193/lib/ruby/gems/1.9.1/gems/gosu-0.10.6-x86-mingw32/lib/gosu.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

C:\Ruby193>


Code:
require "gosu"

class Game_Window < Gosu::Window
  def initialize
    super(640, 480)
    @font = Gosu::Font.new(self, "Arial", 18)
  end
  def draw
    @font.draw("Text", 0, 0, 0) # Error
  end
end
Game_Window.new.show


Please help me!
Topic Camera 2D By Andrek Date 2016-01-31 23:13
Hi everyone! I did this project long ago, years ago, as I did not know to use OpenGL, I create a 2D camera. As my English is very basic i'll be very brief, it is a project to stop halfway and has mistakes but I wanted to show it.

Mediafire: http://www.mediafire.com/download/5r5r6wuzn82zmfz/camera2d.zip

Use to run: [http://s11.postimg.org/4scik9qdb/Screenshot_at_2016_01_31_22_23_23.jpg]

Controls:

* Game:

WASD: Move player
Space: Fly
ESC: Exit

* Editor:

WASD: Move camera
1: Change tile id
Mouse Left: Set tile
Mouse Right: Delete tile
Mouse Wheel: Zoom
ESC: Exit and save

YouTube: https://youtu.be/3HiWPz5-I98

Well, I hope you like it, i hope i can learn more about Ruby and Gosu and i want learn OpenGL :D
Topic Gosu #draw_line bug? By Andrek Date 2016-01-27 00:11
Well i can do what i need, add a screenshot. Ty!!!

[http://s15.postimg.org/kjlufp6cn/image.jpg]
Topic Gosu #draw_line bug? By Andrek Date 2016-01-24 18:16
Well... i used draw_line and i fit it what i need, ty :D
Topic Gosu #draw_line bug? By Andrek Date 2016-01-24 17:23
I have a problem, the quad is filled and i need just lines! what can i do?
Topic Gosu #draw_line bug? By Andrek Date 2016-01-24 17:19
Ok ty bro!
Topic Gosu #draw_line bug? By Andrek Date 2016-01-24 17:08
Hello everybody! i try to draw a line from 0, 0 to 640, 0 and no work, to draw pixels 0, 0 i need use draw_line(0, 1 to 640, 1), i think the coords of screen start in 1, 1 point?

Gosu.draw_line(0, 1, Gosu::Color::RED, 640, 1, Gosu::Color::RED, 0)
Topic Error installing lib gosu By Andrek Date 2016-01-24 16:52
Ah ok, anyway i did not know the diference between both but: the bold part that says, help me, ty!
Topic Error installing lib gosu By Andrek Date 2016-01-24 16:18
Nice! thanks again!!! where i can see the headers, can you give me a link please?
Topic Error installing lib gosu By Andrek Date 2016-01-24 15:42
Thanks bro!!! it's work hahahaha, sorry for no see that :S, how i can add to the section header? my version is Linux Mint 17.3 32bits, Ruby 1.9.3p484 (2013-11-22 revision 43786) [i686-linux] and Gem 1.8.23
Topic Error installing lib gosu By Andrek Date 2016-01-24 03:27
Hi everybody! i'm using Linux Mint and i'm a noob user, i dont speak english and sorry for my bad english

I had this error:
~$ sudo gem install gosu
Building native extensions.  This could take a while...
ERROR:  Error installing gosu:
  ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
The Gosu gem requires some libraries to be installed system-wide.
See the following site for a list:
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- mkmf (LoadError)
  from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
require'
  from extconf.rb:62:in `<main>'
https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux

Gem files will remain installed in /var/lib/gems/1.9.1/gems/gosu-0.10.5 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/gosu-0.10.5/ext/gosu/gem_make.out


then i used: sudo apt-get install build-essential libsdl2-dev libsdl2-ttf-dev libpango1.0-dev \libgl1-mesa-dev libfreeimage-dev libopenal-dev libsndfile-dev

but still i have the problem, please help me.
Topic How to get the key pressed like string By Andrek Date 2015-07-22 12:40
Thanks you!!!! it's work
Topic How to get the key pressed like string By Andrek Date 2015-07-22 11:48
Hi! i want know which key is pressed but like string, like STDIN.gets(), i'm using this code:

def button_down(key)
char = (key + 93).chr
end


That work only with letters but no space key and numbers.

It's for my TextInput class no Gosu's TextInput. Please help me i dont want define each key.
Topic Ruby does not want to create a new object By Andrek Date 2015-07-13 14:36
It's work! thanks a lot, i can understand the operation. Now i can continue with my project, ty!
Topic Ruby does not want to create a new object By Andrek Date 2015-07-12 19:10
Hi everyone! i'm back with Ruby/Gosu from almost 2 year and i have a problem with ruby, first i dont speak very english then i'm confused about where i can post this.

I try to make a data class like this:

@data = Array.new(width, Array.new(height, default_value))

but when i want to change a value like this:

@data[x][y] = terrain_id

No only change that coordinate, Ruby change all coordinate Y in X coordinate, example:


@data[0][1] = 0 # [
[nil, 1, nil], # XY: 0, 1
[nil, 1, nil], # XY: 1, 1
[nil, 1, nil] # XY: 2, 1
]


The problem is that all arrays have the same object_id. I can't understand why, please help me!

Data Class Completed
class Data_Tilemap
  attr_reader(:data)
  attr_accessor(:default_value)
  def initialize(width, height, default_value = 0)
    @width = width
    @height = height
    @default_value = default_value
    #@data = Array.new(width, Array.new(height, default_value))
    @data = []
    width.times { @data.push(Array.new) }
  end
  def [](x, y)
    if x.between?(0, @width - 1) and y.between?(0, @height - 1)
      return @data[x][y]
    else
      return @default_value
    end
  end
  def []=(x, y, value)
    @data[x][y] = value if x.between?(0, @width - 1) and y.between?(0, @height - 1)
    print(
    @data[0].object_id, " ", #=> 21483444
    @data[1].object_id, " ", #=> 21483444
    @data[2].object_id) #=> 21483444
    puts
  end
  def resize(width, height)
    new_data = Array.new(width, Array.new(height, @default_value))
    for x in 0...@width
      for y in 0...@height
        if x.between?(0, width - 1) and y.between?(0, height - 1)
          new_data[x][y] = @data[x][y]
        end
      end
    end
    @data = new_data
    @width = width
    @height = height
  end
end


Edit:

Important information: i save the data like this:
file = File.open(filename, "wb")
Marshal.dump(data, file)
file.close


and load:

file = File.open(@filename, "rb")
@data = Marshal.load(file)
file.close
Topic LoadError: Gosu with Ruby 2.0 By Andrek Date 2013-05-30 19:36
Thanks jlnr :), well i will to downgrade my ruby. :(
Topic LoadError: Gosu with Ruby 2.0 By Andrek Date 2013-05-30 18:23
Hi! i have a error with Gosu's lib when i update my ruby to 2.0.

When i want to use require 'gosu': Look the picture.

Please help.

PD: I have Window 7.
Attachment: require_gosu_error.png (52k)
Attachment: installation_gosu.png - Installation of gosu (34k)
Topic Regular expressions problem By Andrek Date 2013-02-15 04:35
Thanks a lot!! problem solve!!
Topic Regular expressions problem By Andrek Date 2013-02-14 09:49
Hi! i don't know much about regular expressions, however i use them but with this expression i have a problem, look:

/\[\d+\]/.match("text[2]") # => "2" Nice!
/\[\d+\]/.match("text[2]_plus[4]") # => "2" # Problem


So i use:
/\[\d+\]+/.match("text[2]_plus[4]") # => "2" Problem i need "4", the last

I don't know how solve problem, please help me.

PD: I don't speak english, sorry for the bad expressions.
Topic Error installing OpenGL. By Andrek Date 2013-02-05 15:09
Ok thanks a lot! close post please!
Topic Error installing OpenGL. By Andrek Date 2013-02-05 14:09
Nice i understand! but how unistall lol_02's gem ("ruby-opengl-0.60.1-x86-mingw32-ruby19.gem") i install this gem with gem no rubygems, you understand me?

Edit:

I use: gem uninstall ruby-opengl-0.60.1-x86-mingw32-ruby19.gem but => INFO: gem "ruby-opengl-0.60.1-x86-mingw32-ruby19.gem" is not installed

I have a folder with this name: FOLDER[opengl-0.8.0.pre1-x86-mingw32] and FOLDER[ruby-opengl-0.60.1]. I need uninstall the second folder.
Topic Error installing OpenGL. By Andrek Date 2013-02-04 10:09
Ok Spooner, ready, now how to uninstall the old opengl?. Thanks a lot!
Topic Error installing OpenGL. By Andrek Date 2013-01-31 22:13
It's Work! Thanks a lot!!!!!
Topic Error installing OpenGL. By Andrek Date 2013-01-31 00:26
Hi guys, i don't speak english but i will try with the help of Google Translator.

First, i install DevKit of the http://rubyinstaller.org/downloads/ in "C:\Ruby1.9.3\Nueva carpeta\" (Nueva carpeta = New folder) look the picture!

C:\Ruby1.9.3\lib\ruby\site_ruby\devkit.rb
# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('C:\\Ruby1.9.3\\Nueva carpeta\\mingw\\bin') then
  puts 'Temporarily enhancing PATH to include DevKit...'
  ENV['PATH'] = 'C:\\Ruby1.9.3\\Nueva carpeta\\bin;C:\\Ruby1.9.3\\Nueva carpeta\\mingw\\bin;' + ENV['PATH']
end
ENV['RI_DEVKIT'] = 'C:\\Ruby1.9.3\\Nueva carpeta'
ENV['CC'] = 'gcc'
ENV['CXX'] = 'g++'
ENV['CPP'] = 'cpp'


Second, i install the Gosu library using: "gem install gosu", look the picture!

Third, i try install the OpenGL library using: "gem install ruby-opengl", look the picture!

Now, i will to test the libraries:

test-gosu.rb
require 'rubygems'
require 'gosu'
gets

Work!

test-opengl.rb
require 'rubygems'
require 'opengl'
gets

No work!

Please i need help why i don't understand what happens, i can see what say Error but i don't understand why Error!

If you can answer in spanish would be better, Thanks a lot!
Attachment: DevKit.png - DevKit.png (32k)
Attachment: Gosu.png - Gosu.png (25k)
Attachment: OpenGL.png - OpenGL (51k)
Topic Draw Text in the Image By Andrek Date 2012-03-05 13:38
The black background does not delete :S.

[http://s2.subirimagenes.com/imagen/previo/thump_7505650drawtext.png]

And how to change text color?.

Edit:

This is the method:

def draw_text(x, y, string)
  text = Gosu::Image.from_text(@window, string, "Arial", 18)
  @image.splice(text, x, y, :chroma_key => [0, 0, 0, 1])
end
Topic Draw Text in the Image By Andrek Date 2012-03-04 12:19
I'm not going to recreate the code, I will imitate the code :D. I'll remember but I have done a lot of code:

@sprite = Sprite.new # => Make
@sprite.x = x # => Make
@sprite.y = y # => Make
@sprite.z = z # => Make
@sprite.ox = ox # => Make
@sprite.oy = oy # => Make
@sprite.visible = visible # => Make
@sprite.zoom_x = zoom_x # => Make
@sprite.zoom_y = zoom_y # => Make
@sprite.angle = angle # => Make
@sprite.tone = Color.new(red, green, blue[, alpha = 255]) # => Make
@sprite.bitmap = Bitmap.new(width, height) or Bitmap.new(filename) # => Make
@sprite.bitmap.set_pixel(x, y, color) # => Make
@sprite.bitmap.get_pixel(x, y) # => Make
@sprite.bitmap.set_rect(x, y, width, height, color, fill) or @sprite.bitmap.set_rect(Rect.new(x, y, width, height), color, fill) # => Make
@sprite.bitmap.src_rect = Rect.new(x, y, width, height) # => Make
@sprite.bitmap.blt(x, y, Bitmap.new('image.png')[, Rect.new(x, y, width, height) = Rect.new(0, 0, bitmap.width, bitmap.height)]) # => Make
@sprite.bitmap.clear # => Make
Keyboard.trigger?(key) # => Make
Keyboard.trigger_release?(key) # => Make
Keyboard.press?(key) # => Make
Mouse.trigger?(key) # => Make
Mouse.trigger_release?(key) # => Make
Mouse.press?(key) # => Make
Topic Draw Text in the Image By Andrek Date 2012-03-04 11:40
That's what I need, but the text has a black background, is there anyway to remove it? I would use this:

@text = Image.from_text(@window, "Some text", font, 10)
for x in 0..@text.width
  for y in 0..@text.height
    color = @text.get_pixel(x, y)
    if color == [0, 0, 0, 1]
      @text.set_pixel(x, y, [0, 0, 0, 0]
    end
  end
end

Note: Untested code

also need to change the text color, is it possible? Thank you very much :D.
Topic Draw Text in the Image By Andrek Date 2012-03-03 15:10
You can draw a text on an image? example:

@image = Gosu::Image.new(@window, 'media/image.png')
@image.draw_text(0, 0, 'Name: Orc')


I need that merge text pixels to the pixels of the image. Please is very important to me, thank you very much.
Topic How to create an image without image By Andrek Date 2012-03-02 16:15
Ahhhh!!! ok i understand :D.
Topic How to create an image without image By Andrek Date 2012-03-02 15:00
I can not understand how to use clip_to, if I can help I'd appreciate.
Topic How to create an image without image By Andrek Date 2012-03-01 18:18
I do not speak much English but I think I understood what I said and never used pygame/rubygame. I am creating a library with Gosu/TexPlay.

In order not to talk too much I'm going to put a code showing what I want to do:

class Window_Command < Window_Base
  def initialize(width, commands)
    self.width = width
    self.height = 64 # Window height
    @index = 0
    @commads = commands
    @cursor = Sprite.new
    @cursor.bitmap = Bitmap.new('cursor.png') # Bitmap is equal Gosu::Image but Bitmap is created by my.
    self.contents = Bitmap.new(width, commands.length * 32) # width = 192; height = 96
    self.contents.src_rect = Rect.new(0, 0, self.width, self.height) # Not show beyond the window height.
    refresh
  end
  def refresh
    self.contents.clear
    for c in 0...@commands.length # 0, 1, 2
      draw_item(@commands[c], c)
    end
  end
  def draw_item(text, index)
    self.contents.draw_text(0, index * 32, text) # (x, y, string) I need to create this method.
  end
  def update
    if Keyboard.trigger?(:Down)
      @index += 1
    elsif Keyboard.trigger?(:Up)
      @index -= 1
    end
    @cursor.y = @index * 32
    update_src_rect
  end
  def update_src_rect
    case @index
    when 0..1 then self.contents.src_rect.y = 0
    when 3 then self.contents.src_rect.y = 32
    end
  end
end

window_commands = Window_Command(192, ['New Game', 'Continue', 'Exit'])

if Keyboard.trigger?(:Enter)
  case window_commands.index
  when 0 # New Game
  when 1 # Continue
  when 2 # Exit
  end
end


This code creates a window in the game like Final Fantasy, to select options at the beginning of the game, but are only visible two squares the third is created but not visible (src_rect). I hope you find me understand.

My methodology is the RPG Maker XP.
Topic How to edit the rect By Andrek Date 2012-03-01 17:53
Let me give an example of the error code (need an image):

require 'gosu'
require 'texplay'

class Window < Gosu::Window
  def initialize
    super(640, 480, false)
    # Try this code
    @original_image = TexPlay.create_image(self, 32, 32)
    @original_image.rect(0, 0, 5, 5, :color => :red) # later: Comment this line.
    @original_image.insert(Gosu::Image.new(self, 'image.png'), 6, 0)
   
    @cropped_image = TexPlay.create_image(self, 100, 100)
    @cropped_image.splice(@original_image, 0, 0)
  end
 
  def draw
    @cropped_image.draw(0, 0, 0)
  end
end

Window.new.show


I need to use Gosu::Image.new(self, 'image.png') and not 'image.png'.

Look how clear the image(@original_image.insert) when using a rect. Thank you very much.
Topic How to edit the rect By Andrek Date 2012-03-01 12:09
Is what I need but I have a problem:

When I use:

@original_image.insert(image, x, y)

And then use:

@cropped_image.splice(@original_image, x, y)

"splice" ignores the images inserted with the method "insert".

Is there any way to not ignore?. Thank you very much.
Topic How to create an image without image By Andrek Date 2012-03-01 12:03
Thanks but does not solve everything I need. This method is best: http://www.libgosu.org/cgi-bin/mwf/topic_show.pl?tid=726. Thank you very much :D.
Topic How to edit the rect By Andrek Date 2012-02-29 17:10
Hello, I need to know how to edit the rect, something like this:

@image.rect_x = x
@image.rect_y = y
@image.rect_width = width
@image.rect_height = height


or

@image.set_rect(x, y, width, height)

Thank you very much.
Topic How to create an image without image By Andrek Date 2012-02-28 17:12
It worked!, This approach is better because you can use the rect, exactly at this time had that error. Thank you very much: D.

@image = Gosu::Image.new(window, EmptyImageSource.new(100, 100), tileable, rect_x, rect_y, rect_width, rect_height)

Is there any way to edit the rect? so:

@image.rect_x = x
@image.rect_y = y
@image.rect_width = width
@image.rect_height = height


or

@image.set_rect(x, y, width, height)
Topic Bug TexPlay: Always white colors By Andrek Date 2012-02-28 11:24
Hello, I have a bug with TexPLay is that when I use the command:

x = 50
y = 50
color = rand(100) > 50 ? :red : [1, 0, 0, 1]
@image.pixel(x, y, color)


Does not change the pixel to red, it always changes to white. Please help.

Edit:

Problem resolved:

x = 50
y = 50
color = rand(100) > 50 ? :red : [1, 0, 0, 1]
@image.pixel(x, y, :color => color)


When I set the color to use I do so: :color => color.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill