By erisdiscord
Date 2010-04-02 16:29
Edited 2010-04-02 16:35

If you need a tilemap class in Ruby, do have a look at my
gosu-tmx. It's not complete, but contributors are welcome and encouraged.
Right now it loads TMX maps, of course, which can be made with the open source and cross platform
Tiled. If I remember correctly, it doesn't handle maps where different layers have different tile sizes, but this could be added. It also only supports orthogonal maps, but these are probably what you want.
If you do make any changes, please let me know and send them back my way. :)
</shameless-self-promotion>
By banister
Date 2010-06-07 11:58
Edited 2010-06-12 03:48

TexPlay 0.2.910 released
provides:
* source_select, source_ignore, dest_select, dest_ignore (select exactly which source/dest pixels are affected by drawing action)
* support for Gosu::Color
* hopefully fixed opengl crashing problem in some linux distros (using Gosu::MAX_TEXTURE_SIZE)
* rows, columns, to_blob (enables Gosu::Image to be reopened using Gosu::Image.new() and load_tiles())
* bitwise drawing modes no longer affect alpha channels
* Gosu::Image.from_text now patched to automatically cache the new image
* optional :color parameter (sets background color) for TexPlay.create_image, e.g TexPlay.create_image(w, 500, 500, :color => Gosu::Color::GREEN)
Full documentation coming soon
By kyonides
Date 2010-06-15 20:45
Edited 2010-06-15 21:05
Well, I could do that with Chingu (a rubygem) where ippa included a circle drawing method that I modified to make it work like a HP or MP ring for RPG's.
Here's the code (you don't need to install chingu if you don't want to, this would still work since it depends on Gosu API).
def self.draw_ring(cx, cy, r, angle, colors, z=150)
if !colors.is_a? Array or colors.size == 1
self.draw_monocolor_ring(cx, cy, r, angle, colors, z)
elsif colors.size == 2
draw_bicolor_ring(cx, cy, r, angle, colors, z)
elsif colors.size == 4
draw_multicolor_ring(cx, cy, r, angle, colors, z)
end
end
def self.draw_monocolor_ring(cx, cy, r, angle, color, z)
0.step(angle, 1) do |a1|
a2 = a1 + 1
self.window.draw_line(cx + Gosu.offset_x(a1, r),
cy + Gosu.offset_y(a1, r), color,
cx + Gosu.offset_x(a2, r-28),
cy + Gosu.offset_y(a2, r-28), color, z)
end
end
def self.draw_bicolor_ring(cx, cy, r, angle, colors=[], z=150)
0.step(angle, 1) do |a1|
a2 = a1 + 1
self.window.draw_line(cx + Gosu.offset_x(a1, r),
cy + Gosu.offset_y(a1, r), colors[1],
cx + Gosu.offset_x(a2, r-28),
cy + Gosu.offset_y(a2, r-28), colors[0], z)
end
end
def self.draw_multicolor_ring(cx, cy, r, angle, colors=[], z=150)
color = colors[0] if angle > 270 && angle <= 360
color = colors[1] if angle > 180 && angle <= 270
color = colors[2] if angle > 90 && angle <= 180
color = colors[3] if angle > 0 && angle <= 90
0.step(angle, 1) do |a1|
a2 = a1 + 1
self.window.draw_line(cx + Gosu.offset_x(a1, r),
cy + Gosu.offset_y(a1, r), color,
cx + Gosu.offset_x(a2, r-28),
cy + Gosu.offset_y(a2, r-28), 0xFF000000, z)
end
end
There's a need to check if draw_line method is still available or not but it works for me with Gosu 0.7.20. (I've got no deprecation warning.)
You might credit us, shawn, ippa and me for this piece of code.

I'm trying to use the :transparent colour matcher in order to clear "transparent but coloured" pixels out of an image so they are uniformly "transparent black" wherever the alpha channel is 0. I need to do this so that I can know that images that appear identical to the eye are the same, even if they have different "hidden" colour information in them. I'm trying to use:
rect 0, 0, width, height, :filled => true, :color => :alpha, :dest_select => :transparent
:transparent matches no pixels in my image (coloured or black, transparent or opaque), so the image is not changed in any way. Using :dest_ignore instead matches all pixels and clears the whole image.
:dest_select seems to work fine with other specific colours though. I also tried:
line x1, y1, x2, y2, dest_select => :transparent
and
line x1, y1, x2, y2, :trace { :while_color => :transparent }
line x1, y1, x2, y2, :trace { :until_color => :transparent }
with similar effects, where :transparent matched no pixels in my image. I am specifically using :trace to draw an outline around an image as well as to allow me to autocrop (both actions would take forever if done with get/set_pixel), but then I realised I needed to clear out all the coloured transparent areas anyway, so I don't need to use :transparent with :trace any more).
:trace and :dest_select seem to work fine with specific colours, including :alpha.
Any thoughts on this dilemma appreciated (whether I'm doing it wrong or if there is a bug in :transparent). Oh, and thanks for giving us really fast, amazingly versatile functionality like this in Ruby. Really helping me!
(Win7x64 / RubyInstaller 1.9.2 / Texplay 0.2.965 gem)

Ok, i pushed a new 0.2.980 gem, that provides greater control over caching (for improved speed and efficiency)
(1) adds :caching option (to both Gosu::Image.new and TexPlay.set_options... remember it only accepts true and false)
(2) gets rid of auto-caching for TexPlay.create_image() (this should be a significant boost to some games)
(3) also added TexPlay#clear method, it essentially just sticks a filled rect over an image, e.g
img.clear :color => :red, :dest_select => :transparent
is equivalent to:
img.rect 0,0, width, height, :fill => true, :color => :red, :dest_select => :transparent
I would like to thank Mr. Banister for making TexPlay. It is a great complementary tool for Gosu. In my opinion, when it becomes more refined it should come with the standard Gosu library. One of the things I most like, its the macro function. Thats just pure genious. That said, I would like to share some input. Take in consideration I have only used the program for 2 days, so I may be mistaken.
1. get_pixel() function return an array of floats. Why is that? Why not an array of numbers from 0 to 255. The ‘set color’ works like this,
why not the former? Sometimes this floats can get really long.
2. I notice that there can be errors if one manipulates the ‘load_tiles’ version of an image. What I do in my currect project is reload the
image with the ‘ new’ version of the image and everything works fine. Example:
@tiles = Gosu::Image.load_tiles(window, ‘tileset.png’ , 32, 32, true)
#trying to manipulate @tiles[0] is a failure, but…
@tiles[0] = Gosu::Image.new(window, @tiles[0] , true)
#now @tiles[0] can be manipulated; no problem
Anyway, I will share more later. Thanks once again.

TexPlay 0.3.3 released, features a few more :alpha_blend modes
:alpha_blend => :source (default, same as :alpha_blend => true)
:alpha_blend => :dest, uses destination pixels alpha instead of source's alpha for alpha blending
:alpha_blend => :source_with_fixed_alpha, same as :source but doesn't affect alpha channel of destination pixel
:alpha_blend => :dest_with_fixed_alpha, same as :dest but doesn't affect alpha channel of destination pixel
:alpha_blend => false (no alpha blending, same as current behaviour.
nil also accepted)
This version also has gem test support, do the following:
gem install rubygems-testgem install texplaygem test texplayand upload results.
THere's also a few easter eggs in thsi release, require 'texplay/alone' let's you do image manip ostensively without gosu -- (really just wraps and hides gosu stuff): TexPlay.create_image(100, 100).clear(color: :red).save("blah.png")
and require 'texplay/live' a REPL session for image editting; totally undocumented and therefore hard to use :P requires 'pry' gem
Loading...