Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / black borders when pre-stitching a map
- - By Traddles Date 2012-11-21 22:57
I'm trying to use a tileset to build a map but I found that this started really killing my framerate.  So I decided to try using TexPlay's img.splice to build up the final result image and just rendering that (rather than rending each individual tile).

Actually what I'm doing is allowing a map creator to be able to place two tiles on a given location.  This way if there is some tile that has transparent pixels, they can choose what makes sense to be behind that tile on this particular map.

For instance, 4 tiles together make up a flower, but they don't fully fill out the 4 tiles of space, so all around it are transparent pixels so that a map creator could choose to make the secondary tile full green (if the flower is on grass), or grey (if the flower is growing through a crack in the cement or some such).

However, when I use TexPlay to build up this final pre-stitched result image, I get a black boarder around tiles that have transparent pixels.

To see what I mean check out https://github.com/lukebergen/the_editor (sorry for the code, it's a bit messy at this point while I still flesh out the system)

If you swap "stich" to "false" in application/renderer.rb line 64 you'll see that the black boarders around the flowers go away.

Any ideas?
Parent - - By Spooner Date 2012-11-21 23:47
Texplay's splice requires you to specifically set :alpha_blend => true or it will simply replace the pixels, rather than merging them. This is even slower than the default, non-blended, replacement!

I strongly recommend, however, that you just use Gosu's method of rendering a large number of images in your draw method, which is hundreds of times faster than rendering them each frame:

    def draw
      # Recording takes about the same amount of time as drawing them normally, but you only do it once.
      @rendered_tiles ||= $window.record 1, 1 do
        # draw tiles as you would normally
      end

       # Actually drawing the recorded tiles is 100s of times faster than normal.
      @rendered_tiles.draw 0, 0, 0 # Thi
    end

If you need to re-draw the tilemap, just set @rendered_tiles = nil

Another alternative would be to use Ashton::Texture#render, but that isn't a lot faster than using #record.
Parent - By Traddles Date 2012-11-22 00:20
Heh, beat me to it.  Thanks for the tip with splice().  But yeah, I think I prefer the window record method anyway.

Thanks
Parent - - By Traddles Date 2012-11-22 00:19
Ahhh, I figured out a way around this.

Didn't know about Window#record.  If I use that to build up a final "result" image instead of Texplay's splice(), no lines.

Also, it occurs to me that I didn't give any screenshots so:

Original implementation (draw the 32x32 tile images individually every frame.  problems with framerate)


Using Texplay's splice() method to join all the individual 16x16 pixel images into one big "result" image (fixed framerate problem but resulted in black lines around tiles that have transparency)


Finally, using Window#record() instead of splice() to generate the one big "result" image (fixes framerate and 0 black lines!).


So, problem solved.  Though I am still curious what the problem with splice() is.  It seems like it could be pretty handy in other situations :(

Edit: Hmm, img tag does not behave as I would have expected... screenshots attached anyway
Parent - By Spooner Date 2012-11-22 00:35
Ah, I think based on the screenshots the issues isn't about alpha blending. Not entirely sure what it is, but I wouldn't lose sleep over it since you've fixed it now ;)
Up Topic Gosu / Gosu Exchange / black borders when pre-stitching a map

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill