SFML community forums

Help => Graphics => Topic started by: inf4ax on February 09, 2015, 10:15:11 pm

Title: Problem with layers in tilemap system.
Post by: inf4ax on February 09, 2015, 10:15:11 pm
Hello.
I apologize in advance for my weak English
I wrote a class that draws tilemap several layers , but I have a problem because the tile layer "solid " or " object" draw  with a black border ( alpha channel is black )
Shows how it looks more or less
I read data from XML.

Problem exist in layer other than bg, while dot is "player"
"bg" tiles is always appended to vertex array first than "solid" or "objects"
// class declaration TileMap : public sf::Drawable, public sf::Transformable
// i try set sf::BlendAlpha, no effect
while(tile)
                {

                        if(lName == "bg")                                                      
                        {
                                appendTile(x,y,tileNumber);
                        }
                        if(lName == "solid" && tileNumber != -1)       
                        {                                                                                      
                                appendTile(x,y,tileNumber);
                                solidTiles.push_back(SolidTile(x,y));
                        }


                }
 
and append tile function.
void TileMap::appendTile(const sf::Int32 x,const sf::Int32 y, const sf::Int32 GID)
{
        sf::Int32 tu = GID % (m_tileset.getSize().x / tile_width);
        sf::Int32 tv = GID / (m_tileset.getSize().x / tile_height);
        sf::Vertex* quad = &m_vertices[(x + y * width_in_tiles) * 4];
             
        quad[0].position = sf::Vector2f(x * tile_width, y * tile_height);
        quad[1].position = sf::Vector2f((x + 1) * tile_width, y * tile_height);
        quad[2].position = sf::Vector2f((x + 1) * tile_width, (y + 1) * tile_height);
        quad[3].position = sf::Vector2f(x * tile_width, (y + 1) * tile_height);
                       
        quad[0].texCoords = sf::Vector2f(tu * tile_width, tv * tile_height);
        quad[1].texCoords = sf::Vector2f((tu + 1) * tile_width, tv * tile_height);
        quad[2].texCoords = sf::Vector2f((tu + 1) * tile_width, (tv + 1) * tile_height);
        quad[3].texCoords = sf::Vector2f(tu * tile_width, (tv + 1) * tile_height);
}
 
problem looks like that

Thanks in advance.


Title: Re: Problem with layers in tilemap system.
Post by: eXpl0it3r on February 09, 2015, 10:27:52 pm
Your problem is this:
( alpha channel is black )
Just by picking a random color as "alpha" channel, doesn't automatically make that color transparent. Instead I suggest you use a true alpha channel with a format like PNG. And if you really want to keep the masking, then you'll need to use the createMaskFromColor (http://www.sfml-dev.org/documentation/2.2/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34) function when loading the image.

Also black is a rather bad "alpha channel" color. ;)
Title: Re: Problem with layers in tilemap system.
Post by: inf4ax on February 09, 2015, 10:36:43 pm
Thank for reply, but i have a file with true alpha channel ( http://postimg.org/image/w86zjzpe7/ )
I tried the function getColorMaskFrom and did not work
void TileMap::convertColorMask(std::string path)
{
        sf::Image buffer;
        buffer.loadFromFile(path);
        buffer.createMaskFromColor(sf::Color::Transparent,0);
        m_tileset.loadFromImage(buffer);
}
// m_tileset is private member sf::Texture
 
Title: Re: Problem with layers in tilemap system.
Post by: Ztormi on February 10, 2015, 11:16:28 am
Are you using single vertex array for all layers? AppendTile-method sure doesn't seem to support it. Looks to me like you are unintentionally replacing quad instead of adding a new one.
Title: Re: Problem with layers in tilemap system.
Post by: eXpl0it3r on February 10, 2015, 01:10:49 pm
Thank for reply, but i have a file with true alpha channel ( http://postimg.org/image/w86zjzpe7/ )
Nope. JPEG doesn't support alpha channel.
Besides that having compression on the image will fully ruin the pixel image, e.g. one can't even mask it now.
Title: Re: Problem with layers in tilemap system.
Post by: Ztormi on February 10, 2015, 02:28:23 pm
Nope. JPEG doesn't support alpha channel.
Besides that having compression on the image will fully ruin the pixel image, e.g. one can't even mask it now.

If you click it it will open the original PNG image  ;)
Title: Re: Problem with layers in tilemap system.
Post by: eXpl0it3r on February 10, 2015, 03:40:25 pm
Why not like to the actual image in the first place then... ::)

So what happens if you load the image and draw it. No vertex array, nothing special, just loading and drawing. Is it also black?
If not, there's an issue in your code, which you can narrow down by throwing out everything while making sure the error persists.