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 - Toad The Mushroom coder

Pages: [1]
1
Graphics / Re: Application will freeze when using sf::Clock
« on: September 16, 2018, 06:30:58 pm »
You should probably change delta_time == 50 to delta_time >= 50. Right now if your delta time ever jumps from, say 49 to 51, your code will never update the text again.

Sorry for taking that long to reply. Tested it and yeah, IT WORKS! Thank you so much! This has been a really long issue for me and I am happy to get over it!

2
Graphics / Application will freeze when using sf::Clock
« on: September 14, 2018, 09:06:00 pm »
Hello There!

Lately, I have been trying to get used to the "sf::Clock" class in SFML. Specifically, I have been trying to make a typing text effect. Here is the function responsible for drawing the text with said effect:

void Dialogue::Type(sf::RenderWindow &window)
{
        delta_time = curr_time - rec_time;

        if(delta_time == 50 && chr < str.size())
        {
                chr++;
                text.setString(sf::String(str.substr(0, chr)));
                rec_time = clock.getElapsedTime().asMilliseconds();
                curr_time = rec_time;
        }
        else
                curr_time = clock.getElapsedTime().asMilliseconds();

        window.draw(text);
}

and inside my main function and while(window.isOpen()) loop, I call the function:

window.clear();
//-------------//
dial.Type(window);
//--------------//
window.display();

Even if I haven't noticed any error with the way I wrote my code, the application will freeze randomly when typing a phrase. The phrase was  "This is a typing-effect test" and the application would be stuck in random times (for example it would write "This is a typ" and then it wouldn't continue). The window would respond but the code would not execute any further as it should. The same behaviour was shown other times I tried using sf::Clock, like when I tried making a timer (the timer would stop counting the time at random). What is causing that and how can I repair it? (I am using Visual Studio 2017)

3
Graphics / Re: How can I create global sprites?
« on: January 12, 2018, 02:18:14 pm »
You can organize your sprites and textures as members of C++ classes or structs to keep things from getting "messy". Those classes and structs themselves can be allocated on the heap if need be.

So declaring textures and sprites on a class does not have the same effect as declaring them in a function?

4
Graphics / How can I create global sprites?
« on: January 04, 2018, 03:28:26 pm »
Hello!

So, I have finished creating a project on SFML. However, I noticed that my code inside the int main() function was too messy, especially with those sprites' and textures' declarations "cramming" the function. As I am aware, it is impossible to declare and create sprites in different functions than the one containing the 'window.draw' and 'window.display' commands, as they will be destroyed as soon as the function is done being executed, due to being local to said function only (Just like when declaring variables).

My question is: can we create a "global sprite" system similar to variables? What I mean is that, if you want to have global variables that can be used by all the functions in your project, you declare them in a header file, and define them in a C++ source file (I do this, at least, and it works for most types of variables). Can the same be done here?

5
Graphics / Texture appears in a weird way (Solved)
« on: January 01, 2018, 12:47:37 pm »
Hello!
So recenty I tried to set a texture for a floor sprite I was making for a test I was doing. I was trying to create a Sprite named floor, in which the texture "terrain" would repeat itself, creating something similar to the ground in Super Mario Bros. Here is my code, where I define the afore mentioned:

sf::Texture terrain;
terrain.create(50, 50);
if (!terrain.loadFromFile("img/tile.png"))
{
      std::wcout << L"No tile.png exists";
}
terrain.setRepeated(true);

sf::Sprite floor;
floor.setScale(10000.f, 1000000000.f);
floor.setPosition(0.f, 4700.f);
floor.setTexture(terrain);
 

For reference, the image tile.png is the following and its size is 50*50 (pixels)


However, when I draw the floor, I get this:


The brown box right Mario is the floor Sprite I defined above.
As you can see, the texture "terrain" is not repeated across the srite as intended, but rather the floor has a brown texture. How can I fix this? Am I doing something wrong?

Pages: [1]