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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Zantax

Pages: [1]
1
Graphics / Re: Some Text is Blurry
« on: November 04, 2017, 09:20:56 pm »
I calculated the positions and put them into separate integers and that fixed the problem, thanks!

For anyone else who has trouble here's the new code.
        sf::Text newText ("New Map",font,20);
        sf::Text loadText("Load Map", font, 20);
        int x1 =  (INPUT_W / 2) - newText.getLocalBounds().width / 2;
        int y1 =  (INPUT_H / 3 * 1) - newText.getLocalBounds().height / 2;
        int x2 =  (INPUT_W / 2) - loadText.getLocalBounds().width / 2;
        int y2 =  (INPUT_H / 3 * 2) - loadText.getLocalBounds().height / 2;
        newText.setPosition(x1,y1);
        newText.setFillColor(sf::Color::Black);
        loadText.setPosition(x2,y2);
        loadText.setFillColor(sf::Color::Black);

I'm assuming there's some sort of issue with data loss with converting inside vs outside the setPosition command. Just my guess I've never looked too far into that stuff.

2
Graphics / Some Text is Blurry
« on: November 04, 2017, 07:29:23 pm »
I'm trying to make a simple starter menu for an application with two buttons, new and load. The way I figured I'd do it is have two rectangles with text on top. After running I noticed an odd issue that I can't figure out. One piece of text seems to be blurry while the other is crisp and clean. They are both using the same font, size, etc so I'm not sure why one acts differently then the other. Here's an image of it https://i.imgur.com/CGLuoyO.png and here's the code being used (sorry for the mess I'm just messing around with it atm)
        sf::RenderWindow InputWindow(sf::VideoMode(INPUT_W, INPUT_H), "Main Menu");
        InputWindow.clear(sf::Color::Black);

        sf::Font font;
        if (!font.loadFromFile("times.ttf"))
        {
                std::cout << "Font not loaded!";
        }

        int button_width = 100, button_height = 50;
        sf::RectangleShape NewButton(sf::Vector2f(button_width,button_height));
        NewButton.setPosition(sf::Vector2f((INPUT_W / 2)-button_width/2, (INPUT_H / 3 * 1) - button_height/2));
        NewButton.setFillColor(sf::Color::White);

        sf::RectangleShape LoadButton(sf::Vector2f(100, 50));
        LoadButton.setPosition(sf::Vector2f((INPUT_W / 2) - button_width/2, (INPUT_H / 3 * 2) - button_height/2));
        LoadButton.setFillColor(sf::Color::White);

        sf::Text newText ("New Map",font,20);
        sf::Text loadText("Load Map", font, 20);

        newText.setPosition(sf::Vector2f((INPUT_W / 2) - newText.getLocalBounds().width /2, (INPUT_H / 3 * 1)- newText.getLocalBounds().height /2));
        newText.setFillColor(sf::Color::Black);
        loadText.setPosition(sf::Vector2f((INPUT_W / 2) - loadText.getLocalBounds().width /2, (INPUT_H / 3 * 2) - loadText.getLocalBounds().height /2));
        loadText.setFillColor(sf::Color::Black);

        InputWindow.draw(NewButton);
        InputWindow.draw(newText);
        InputWindow.draw(LoadButton);
        InputWindow.draw(loadText);

        InputWindow.display();

On a side note anyone have a better method for centering text?  :P

3
General / Advice for Collision Detection and/or Tile Maps
« on: June 07, 2017, 08:49:47 pm »
Sorry if this seems like a broad topic, but I'm just looking for some general advice or suggestions. Basically what I'm trying to do is create a top-down view of a map and add a masking fog over the whole thing. I set up a test that works fairly well, the map below and the fog are tile maps that work independently of each other. When a character's field of view (a circle shape placed below the character that moves with them) touches a point on the fog map that point becomes transparent revealing the map below and any entities that might be there. When the character moves away the terrain remains visible, but any entities are now invisible. Again it works almost exactly as I wanted, except that I am using the bounding rectangle for the character's vision which ends up making everything very blocky looking. Here is an example of what I'm talking about (excuse my bad test art) http://imgur.com/a/W2PiO

So my initial idea is to add pixel perfect collision on the character's view. However I plan on having many units on screen at once, and I'm not sure if that could negatively impact the performance at all. Currently the way it's set up, every frame a loop goes through every point in the fog map and checks it against .contains on the bounding rectangle of the vision circle. I'm not sure if this is the best method or not, but I can't seem to find another solution at the moment. I'm also not sure if there is something better to use instead of a tile map for creating fog. Normally I would just try out the pixel perfect method but sadly I haven't had the time to implement and test it myself and it's been bugging me. Any ideas are greatly appreciated!

4
General / Re: Editing Tiles in a Tilemap
« on: April 05, 2017, 04:51:17 pm »
My approach to this would probably be something along the lines of

for(int i = 0; i < map.quad.size() ; i++
{
  sf::FloatRect a = sf::FloatRect(map.quad.position.x , map.quad.position.y, map.quad.getSize().width, map.quad.getSize().heigth);
  if (player.getGlobalBounds().intersects(a)
  {
      map.quad.position = [insertPositionHere]
      map.quad.texCoords = [insertNewTexCoordsHere]
  }
}

That was my initial idea but I figured running a loop checking every single point every time you wanted to update would be very inefficient and could possibly cause lag if the player is moving around a lot.

that's one approach that I can think of off the top of my head. I for one wouldn't use Quads and would make my own "Tile" class.

I was so focused on the tutorial's coding I didn't even consider this idea. That might be exactly what I'm looking for, thank you! I knew I was just overthinking things. As soon as I get some spare time I'm going to try and write that up!

5
General / Re: Editing Tiles in a Tilemap
« on: April 05, 2017, 02:36:29 am »
I have not seen those functions before, they will definitely help simplify things!

However I'm still having trouble figuring out how to actually edit an individual tile/point. Say I do something like this (rough code just for demonstration)

sf::Rect Bound=player.getglobalbounds;
if(Bound.intersects(25,50))
    Change Point at 25, 50

What would I have to do in order to actually edit that specific point?

6
General / Editing Tiles in a Tilemap
« on: April 04, 2017, 06:47:45 pm »
I'm trying to learn SFML on my own, but I'm a bit stumped right now and in need of some help. I've followed the official tile map tutorial (https://www.sfml-dev.org/tutorials/2.4/graphics-vertex-array.php) and have it running with a basic tileset I made and a moveable player which for now is just a circle.

The problem I've run into is how to make the player and tilemap interact with eachother. I believe I know the basics on how to find the player's location on the tilemap, get their position and divide it by the tile width and height to find it's the closest x and y on the map (please correct me if I have that wrong).

What I'm trying to figure out now is what to do once I found the coordinates of the point the player is touching. The idea I have is to implement a fog of war style map. The tilemap will be completely black. When the player touches a corner in a quad, that corner will become transparent and use the built in gradient system to create a sort of fog that connects to the other corner.

Basically my question is how do I use the coordinates of a point in a vertex array to interact with the point and change its color.

Sorry if I tend to ramble a bit. I hope the question isn't too broad. I would post what code I have so far but I'm not at home.

Pages: [1]