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 - Wake

Pages: [1]
1
Graphics / Re: Scrolling tilemap issue: black bars
« on: May 19, 2021, 04:21:42 am »
I had the exact same problem. Big, ugly, obvious black lines between tiles.

Rendering everything to a sf::RenderTexture got rid of it.

Below is my RenderTexture Initialization Function & Render Function from my GameState:

Code: [Select]
void GameState::initRenderTexture()
{
this->renderTexture.create(this->window->getSize().x, this->window->getSize().y);
this->renderTexture.setSmooth(true);
this->renderSprite.setTexture(this->renderTexture.getTexture());
this->renderSprite.setTextureRect(sf::IntRect(0, 0, this->window->getSize().x, this->window->getSize().y));
}

void GameState::render(sf::RenderTarget* target)
{
if (!target)
target = this->window;

/*Items Rendered to Render Texture*/
this->renderTexture.clear();
this->renderTexture.setView(this->view);
this->renderTileMap(this->renderTexture);
this->renderSprite.setTexture(this->renderTexture.getTexture());
this->renderPlayer(this->renderTexture);
this->renderTexture.display();
target->draw(this->renderSprite);

/*Items Rendered with Default Window View*/
this->window->setView(this->defaultWindowView);
if (this->isPaused)
this->renderPauseMenu(*target);
}

I'm still getting some weird less-noticeable artifacts and have come to the conclusion that rendering lots of little 32.f x 32.f sprite tiles is bad practice.

You essentially want to use larger sprites and fit as much as possible into the .png texture via GIMP or Photoshop.

I'm using this guy's RPG level Tileset for practice: https://pipoya.itch.io/pipoya-rpg-tileset-32x32.

For example, his trees are made up of 4 32.f x 32.f squares... You don't want to set trees like this... You actually want to grab the entire 64.f x 64.f tree... Or better yet, a larger bundle of trees... As large a possible to fit your needs.

The only thing you can do is make it less noticeable is by fitting as much as possible into the PNG texture and making the tile square as large as possible.

Even with this advice, you'll never get 100% avoidance of floating point artifact issues. You'll still get them on the edges of places where tiles are placed next to each other.

Overall... Less Environmental Tiles = Less Floating Point Tile Artifacts plain and simple...

Hope this helps people save some time searching for an answer to this problem :)

2
General discussions / Re: SFML Blueprints - Another SFML book
« on: January 27, 2021, 03:37:10 am »
Hi, I'm really enjoying the 2nd chapter. However, I'm extremely new to templates and there is so much to do before a single bug test.

I looked at the source code, but I'm at the end of the "Managing user inputs" subchapter.

I moved all the methods for classes using Templates to .tpl files and created the "book namespaces" as you have it.

I'm getting the following error on the "if(action.first.Test())" line. I've checked everything, but the source code provided has the entire chapter's solution. I really want it to compile as you said it should at the end of this subchapter.

Any help would be appreciated.

 Severity   Code   Description   Project   File   Line   Suppression State
Error   C2228   left of '.Test' must have class/struct/union   Chapter 2   C:\Users\lumit\Desktop\SFML Blueprints\Chapter 2\Chapter 2\ActionTarget.tpl   29   


Code: [Select]
template<typename T>
void ActionTarget<T>::ProcessEvents()const
{
    for(auto& action : m_eventsRealTime)
    {
        if(action.first.Test())
           action.second(action.first.m_event);
    }
}

3
Hi, so I made a std::unordered_map to contain my user input key bindings. I have a struct called "Bindings" that contains the following members.
Code: [Select]
struct Binding
{
Binding() {}

Binding(InputType inputTypes, sf::Event::EventType eventType1, sf::Event::EventType eventType2,
    sf::Keyboard::Key keyCode1, sf::Keyboard::Key keyCode2,
sf::Mouse::Button mouseCode1, sf::Mouse::Button mouseCode2)
            : my_InputTypes{ inputTypes }, m_enumEventType1 {eventType1}, m_enumEventType2 { eventType2 },
        m_keyCode1{ keyCode1 }, m_keyCode2{ keyCode2 }, m_mouseCode1{ mouseCode1 },
    m_mouseCode2{ mouseCode2 }{}

InputType my_InputTypes;
sf::Event::EventType m_enumEventType1;
sf::Event::EventType m_enumEventType2;
sf::Keyboard::Key m_keyCode1;
sf::Keyboard::Key m_keyCode2;
sf::Mouse::Button m_mouseCode1;
sf::Mouse::Button m_mouseCode2;


};

using BindingMap = std::unordered_map<std::string, Binding >;

I read a .csv file to enter my bindings.
Code: [Select]
void EventManager::LoadBindings()
{
std::ifstream keyBindings("Keys.csv");

if (!keyBindings.is_open()) { std::cout << "Error loading Keys.csv..."; }

int number_of_lines = 0;
std::string lineCount;

while (std::getline(keyBindings, lineCount))
++number_of_lines;
std::cout << "Number of lines in .csv file: " << number_of_lines << '\n';

keyBindings.close();
keyBindings.open("Keys.csv");

std::string mapKey;
std::string myInputType;
std::string eventType1;
std::string eventType2;
std::string keyCode1;
std::string keyCode2;
std::string mouseCode1;
std::string mouseCode2;

for (int i=0; i <= (number_of_lines-1); ++i)
{
std::getline(keyBindings, mapKey,',');
std::getline(keyBindings, myInputType,',');
std::getline(keyBindings, eventType1,',');
std::getline(keyBindings, eventType2, ',');
std::getline(keyBindings, keyCode1,',');
std::getline(keyBindings, keyCode2,',');
std::getline(keyBindings, mouseCode1,',');
std::getline(keyBindings, mouseCode2,'\n');

std::cout << mapKey << "|"
<< stoi(myInputType) << "|"
<< stoi(eventType1) << "|"
<< stoi(eventType2) << "|"
<< stoi(keyCode1) << "|"
<< stoi(keyCode2) << "|"
<< stoi(mouseCode1) << "|"
<< stoi(mouseCode2) << '\n';

m_bindingMap.insert(std::pair <std::string, Binding>
(mapKey, { static_cast<InputType>(stoi(myInputType)),
   static_cast<sf::Event::EventType>(stoi(eventType1)),
static_cast<sf::Event::EventType>(stoi(eventType2)),
       static_cast<sf::Keyboard::Key>(stoi(keyCode1)),
               static_cast<sf::Keyboard::Key>(stoi(keyCode2)),
   static_cast<sf::Mouse::Button>(stoi(mouseCode1)),
   static_cast<sf::Mouse::Button>(stoi(mouseCode2))}));

}
keyBindings.close();
PrintMap();
}

void EventManager::PrintMap()
{
for (auto element : m_bindingMap)
{
std::cout << element.first << " :: " << static_cast<int>(element.second.my_InputTypes)
   << " :: " << static_cast<int>(element.second.m_enumEventType1)
   << " :: " << static_cast<int>(element.second.m_enumEventType1)
                       << " :: " << static_cast<int>(element.second.m_keyCode1)
                       << " :: " << static_cast<int>(element.second.m_keyCode2)
                       << " :: " << static_cast<int>(element.second.m_mouseCode1)
                       << " :: " << static_cast<int>(element.second.m_mouseCode2)
   << std::endl;
}
}
The map works perfectly and is tested... Now, I'm trying to make a multikey bool that flags "true" if 2 or more buttons are pressed at the same time.
Code: [Select]
bool EventManager::TestEvent(Binding binding, sf::Event event)
{
//MultiKeyEvents
if ((binding.my_InputTypes == InputType::MultikeyEvent) &&
(binding.m_enumEventType1 == event.KeyPressed) &&
(binding.m_enumEventType2 == event.MouseButtonPressed) &&
(binding.m_keyCode1 == event.key.code) &&
(binding.m_mouseCode1 == event.mouseButton.button))
{
return (true);
}

return (false);
}

For this example, the keycode = 0 for "A" and the mouse button code = 0 for "Left Mouse Button". I'm trying to register "true" when they are both pressed together. However, with this if statement it will register "true" if I press "A" or the "Left Mouse Button" separately. What am I missing here!? I only want it to be "true" if they are both pressed at the same time.

4
Are you calling playItemChime every frame and thus calling play every frame while m_IsColliding is true?

When you call play on a sound that is already playing it restarts it from the beginning, so if that's what you're doing your sound is restarting every frame so you never have enough time hear it.

WTF, why do you use a picture to show text?

My collider class is checking for the collision and displaying the "Item!" message bubble every frame. Our do you suggest I connect this to trigger a sound  outside of "while(isOpen) loop? I've been busting my brain on this all day!

5
Good call!

I had it in the while (window.isOpen()) loop!

I guess I'll need to make a timer that doesn't this collision check at regard intervals way less than 1 frame. :)

I think it's easier to see the image of the code.

How do I do the code tags on this platform? On learncpp.com it was
Code: [Select]


6
Hi,

Please see the images below;

#Image 1: Collision.hp - I have a sf::SoundBuffer m_SoundBuffer; & sf::Sound m_Sound member variables.

#Image 2: Collision.cpp - In the Collision Class Constructor, I'm loading the .wav to the m_SoundBuffer and setting it to m_Sound;

#Image 3: Collision.cpp - I want the void function to play the sound if (bool m_IsColliding == true).

Result = The sound doesn't play when colliding with the item! :/


7
I got it to work in a hacky kind of way using the sf::RectangleShape's position, then offsetting it via trial and error.

I would like to learn a clean way to play text directly in the center of shapes and sprites though :)


8
Hi,

Please see the attached images below.

Image #1 shows how I set the origin of the sf::RectangleShape.
I want it to be in the dead center. So half of x & y.

Image #2 shows how I'm trying to set the position of the text to the origin of the sf::RectangleShape.

Image #3 shows that the text is nowhere near the text box. What happened?

I saw you can set an origin for the sf::Text. Should I make it half the font size for x & y? Does that even matter?

Best,
Wake

9
Hey, thanks for the feedback!

I read another thread and it clicked!

I made sf::Font m_ItemTextFont; & sf::Text m_ItemText; member variables in my class and loaded the .ttf file to sf::Font m_ItemTextFont in my constructor. Then, I set the font of sf::Text m_ItemText; using  sf::Font m_ItemTextFont; and it worked!

For anyone else experiencing this issue, I included the screen captures here.


10
Graphics / Re: How the heck does origin work? Extremely confused.....
« on: January 17, 2021, 11:53:28 pm »
OMG this thread saved my life!

I included screen captures of the way to return sf::Text with sf::Font from a class to the main window.draw() function!  8)

#1 Rule!

YOU MUST make sf::Font a MEMBER VARIABLE OF THE CLASS and load the .ttf to the sf::Text Member Variable in the constructor... Make sf::Text another member variable and set the font using the sf::Font member variable in the constructor.


11
Hi,

Please see the attached images.

So, I've built a collision class and I want to display a rectangle object with some text in it when there is a collision between the player and the pickup item.

I got the rectangle shape to appear and disappear perfectly on collision, however when I do the same process for the sf::Text, I get an error in Virtual Studio 2019 that states:

"Unhandled exception at 0x00007FFAB2D169DB (sfml-graphics-d-2.dll) in RPG.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

The text draws perfectly in the main function, however, I'd like to return this from the Collision class and create a switch for different messages depending on the item being picked up.

Best,
Wake

Pages: [1]
anything