Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with layers in tilemap system.  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

inf4ax

  • Newbie
  • *
  • Posts: 2
    • View Profile
Problem with layers in tilemap system.
« 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.


« Last Edit: February 09, 2015, 10:28:09 pm by inf4ax »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10879
    • View Profile
    • development blog
    • Email
Re: Problem with layers in tilemap system.
« Reply #1 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 function when loading the image.

Also black is a rather bad "alpha channel" color. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

inf4ax

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Problem with layers in tilemap system.
« Reply #2 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
 

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Problem with layers in tilemap system.
« Reply #3 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10879
    • View Profile
    • development blog
    • Email
Re: Problem with layers in tilemap system.
« Reply #4 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: Problem with layers in tilemap system.
« Reply #5 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  ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10879
    • View Profile
    • development blog
    • Email
Re: Problem with layers in tilemap system.
« Reply #6 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/