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

Author Topic: Why does my tile draw a way darker color than the rest of my tiles?  (Read 2701 times)

0 Members and 1 Guest are viewing this topic.

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
I have made a small platformer with no issues. But I created a roguelike top down framework and for some reason the opendoors facing one direction are way darker. There is no sf::Color code or anything it is treated no different than any other texture sprite.
Just initialized setTexture() then for each tile in map window.draw()? What could be the issue?



//INITIALIZE TEXTURES//
enum textures{ENEMYTEX = 0, PLAYERTEX, GUNHANDTEX, BULLETTEX, MENUBLOCKTEX, WALLTEX, FLOORTEX1,FLOORTEX2,
FLOORTEX3,FLOORTEX4,UNUSEDTEX,SMALLHEALTHTEX,MEDIUMHEALTHTEX,SMALLMANATEX,MEDIUMMANATEX,GOLDSACKTEX,
UPSTAIRSTEX,DOWNSTAIRSTEX,CLOSEDDOORTEX,OPENDOORTEX,CLOSEDDOORROTATEDTEX,OPENDOORROTATEDTEX};
enum sounds{ENEMYHURT = 0, ENEMYDEATH, GUNSHOT, SAVEME, DONTWORRY, PROTAGANIST1, PROTAGANIST2
            ,NORMALBACKGROUND,BOSSBACKGROUND};
inline void loadTextures()
{
    textureArray[ENEMYTEX].loadFromFile("data/images/enemy.png");
    textureArray[PLAYERTEX].loadFromFile("data/images/player.png");
    textureArray[GUNHANDTEX].loadFromFile("data/images/gunhand.png");
    textureArray[BULLETTEX].loadFromFile("data/images/bullet.png");
    textureArray[MENUBLOCKTEX].loadFromFile("data/images/menublock.png");
    textureArray[WALLTEX].loadFromFile("data/images/wall.png");
    textureArray[FLOORTEX1].loadFromFile("data/images/floor1.png");
    textureArray[FLOORTEX2].loadFromFile("data/images/floor2.png");
    textureArray[FLOORTEX3].loadFromFile("data/images/floor3.png");
    textureArray[FLOORTEX4].loadFromFile("data/images/floor4.png");
    textureArray[UNUSEDTEX].loadFromFile("data/images/unusedtile.png");
    textureArray[SMALLHEALTHTEX].loadFromFile("data/images/smallhealth.png");
    textureArray[MEDIUMHEALTHTEX].loadFromFile("data/images/mediumhealth.png");
    textureArray[SMALLMANATEX].loadFromFile("data/images/smallmana.png");
    textureArray[MEDIUMMANATEX].loadFromFile("data/images/mediummana.png");
    textureArray[GOLDSACKTEX].loadFromFile("data/images/goldsack.png");
    textureArray[UPSTAIRSTEX].loadFromFile("data/images/upstairs.png");
    textureArray[DOWNSTAIRSTEX].loadFromFile("data/images/downstairs.png");
    textureArray[CLOSEDDOORTEX].loadFromFile("data/images/closedDoor.png");
    textureArray[OPENDOORTEX].loadFromFile("data/images/openDoor.png");
    textureArray[CLOSEDDOORROTATEDTEX].loadFromFile("data/images/closedDoorRotated.png");
    textureArray[OPENDOORROTATEDTEX].loadFromFile("data/images/openDoorRotated.png");
}

//INITIALIZE TEXTURES ON TILE SPRITE//
inline Tile::Tile(short type,sf::Vector2f position)
:GameEntity(position,TileSize)
{
    switch(type)
    {
        case Unused:
            GameEntity::setTexture(UNUSEDTEX);
            break;
        case Wall:
            GameEntity::setTexture(WALLTEX);
            break;
        case Floor:case Corridor:
            GameEntity::setTexture(FLOORTEX1);
            break;
        case ClosedDoor:
            GameEntity::setTexture(CLOSEDDOORTEX);
            break;
        case ClosedDoorRotated:
            GameEntity::setTexture(CLOSEDDOORROTATEDTEX);
            break;
        case OpenDoor:
            GameEntity::setTexture(OPENDOORTEX);
            break;
        case OpenDoorRotated:
            GameEntity::setTexture(OPENDOORROTATEDTEX);
            break;
        case DownStairs:
            GameEntity::setTexture(DOWNSTAIRSTEX);
            break;
        case UpStairs:
            GameEntity::setTexture(UPSTAIRSTEX);
            break;
    }
    setColor(sf::Color(255,255,255,255)); //No effect
}

//DRAW TILE SPRITES WITHIN VIEW BOUNDS//
inline void Tile::draw(WINDOW& appWindow)
{
    appWindow.draw(*this);
    if(thingsOnTile.size() > 0)
    {
        appWindow.draw(*thingsOnTile[thingsOnTile.size()-1]);
    }
}
inline void Map::draw(WINDOW& appWindow,sf::View& view)
{
     sf::FloatRect viewRect = sf::FloatRect{view.getCenter().x-(view.getSize().x/2),
                            view.getCenter().y-(view.getSize().y/2),
                            view.getCenter().x+(view.getSize().x/2),
                            view.getCenter().y+(view.getSize().y/2)};
     short yMax = floor(viewRect.height/TileSize.y);
     short yMin = floor(viewRect.top/TileSize.y);
     if(yMin < 0) yMin = 0;
     short xMax = floor(viewRect.width/TileSize.x);
     short xMin = round(viewRect.left/TileSize.x);
     if(xMin < 0) xMin = 0;
     print("Y MIN:" + tostr(yMin) + "Y MAX: " + tostr(yMax));
     print(viewRect.top);
     for(int y = yMin; y <=yMax; ++y)
         for( int x = xMin; x <=xMax; ++x)
         {
             print(x+(y*tilesWide));
                this->at((y*tilesWide)+x).draw(appWindow);
         }
}
//Although the viewrect thing is irrelevent same thing happens when i just go auto i : Tiles window.draw(i);
 

Its a very strange thing because I have one tile for a door oriented vertically and one for a door oriented horizontally. and all I did is rotate the horizontal one to vertical in GIMP and save it and it comes out way darker than it looks in the PNG file when I draw it in the program. I know I could do the rotations in the program but meh. I honestly will have to try I guess. Just seems very strange that all I did was rotate the PNG file and save it as another PNG file and then add it to the program and it comes out all blacked out like its messed up transparency or something.

I can fix it by doing

        case OpenDoor:
            GameEntity::setTexture(OPENDOORROTATEDTEX);
            setRotation(90);
            move(50,0);
            break;
with the texture that doesn't mess up. But still dunno why it occurs.
« Last Edit: July 11, 2019, 06:34:26 am by nathanmyersc »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #1 on: July 11, 2019, 10:32:32 pm »
Might be of some use to also provide here the image files that are causing this issue.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #2 on: July 12, 2019, 04:04:21 pm »
Ok sure. I have been wondering if it is related to the image itself but I have tried lots of different ways of exporting the png file with no difference. removed the alpha channel that is on by default. Having the same issue with some of the images that compose the player character;

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #3 on: July 12, 2019, 08:24:20 pm »
openDoor is definitely darker than closedDoor, so the problem is with your images.

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #4 on: July 12, 2019, 09:11:47 pm »
No unfortunately that's not it. I had messed around with the colors to see if I could correct it. But with the sword and shield hand it renders on screen darker and different than the picture shows.
For example.

OpenDoor Renders really dark and unseeable almost just faintly but OpenDoorRotated renders as would be expected
« Last Edit: July 12, 2019, 09:14:55 pm by nathanmyersc »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #5 on: July 12, 2019, 10:38:44 pm »
Although there are clear differences between the brightnesses of the open and closed door images you showed first, if you are no longer using those images, it might be the problem. I do wonder why you provided those images at all if those aren't the ones you are using.

It's probably best - at this point - to provide a minimal and complete example so that others can test the code themselves (that can help people find the problem sooner) and also may help you find the problem in the process. Please read the forum post that I just linked.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Paul

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #6 on: July 16, 2019, 11:52:53 pm »
OpenDoor Renders really dark and unseeable almost just faintly but OpenDoorRotated renders as would be expected

These two files also have different PNG format, it's clear from file size.

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Why does my tile draw a way darker color than the rest of my tiles?
« Reply #7 on: July 17, 2019, 12:48:10 pm »
Thanks for the response I actually figured it out. I tried to make a small example outlining the problem but couldn't and when I looked around for a while I found out that the array i had that held all the textures i had initialized 18 slots in the array but there were 24 textures put into the array. So weirdly enough it still worked and i could use the textures but they were colored strangely. don't really understand why it worked though.

 

anything