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

Pages: [1] 2
1
Instead of completely reloading the font from file, you could make a copy of the sf::Font instance before rendering characters, and use it to reset your working sf::Font instance from time to time by assigning to it. This will reuse the same underlying FreeType objects under the hood but start with new empty textures.

EDIT: forget what I said, the textures are also copied with the font. I was expecting it was not doing it.
Then I have no idea besides patching SFML code to implement clearing font textures.

2
General discussions / Re: Music does not rewind.
« on: May 14, 2024, 07:01:51 pm »
This is a known bug which was fixed in SFML 2.6
https://github.com/SFML/SFML/pull/2175

3
Graphics / Re: Align the text perfectly centered inside any shape
« on: May 12, 2024, 01:43:36 am »
You are making a copy of the text object. Setting the position on the copy has no impact on the original object.

4
You are trying to achieve a letterbox effect.
There is an example implementation on the wiki: https://github.com/SFML/SFML/wiki/Source:-Letterbox-effect-using-a-view

5
Graphics / Re: shifting center on rotation
« on: April 20, 2024, 10:06:10 am »
You need to set the origin at the center, which is the size divided by two. For an odd size, that would have a fractional part.
To get the intuition, think about a 1 * 1 sprite. Then, you need the origin to be (0.5, 0.5).
So for your 49 * 35 sprite, you need to set the origin to (24.5, 17.5).

6
General / Re: I found a range-based for loop issue with vs2012
« on: December 19, 2023, 07:12:44 am »
The range-based for loop in comments is copying each item to use it in the the loop body.
You probably want to use a reference to each item with type auto& instead of a copy with type auto.
It looks like a const reference would also be possible with const auto&.

Try this:
for (const auto& content : m_verticesAndTexture)
{
    states.texture = &content.second;
    target.draw(content.first, states);
}

If you can enable c++17, you could use structured bindings to make this more readable:
for (const auto& [vertices, texture] : m_verticesAndTexture)
{
    states.texture = &texture;
    target.draw(vertices, states);
}

7
Graphics / Re: possible bug with sf::circleShape points not updating
« on: October 12, 2023, 11:09:17 pm »
This is expected. getPoint ignores the shape transform.

The returned point is in local coordinates, that is, the shape's transforms (position, rotation, scale) are not taken into account.

If you want transformed positions, you can get the shape transform (getTransform) and use it to transform the points (transformPoint).

8
Graphics / Re: National letters - input text on screen
« on: August 06, 2023, 10:26:53 pm »
If name_input_string is an std::string and you do:
Code: [Select]
name_input_string += ev->text.unicode;then the 4-bytes unicode character will be narrowed down to only one byte and lose information.
For example "ń" (unicode character U+0144) becomes "D" (unicode character U+0044). Only the least significant byte is added to the string.

You can use sf::String instead of std::string to store unicode characters.
Alternatively you could encode unicode characters to UTF-8 encoding to store them in an std::string.

9
Graphics / Re: Using sf::Text and sf::Font in Windows ×64 MinGW
« on: May 30, 2023, 10:59:21 pm »
The linker error tells FreeType is not linked.
If you link SFML statically, then you need to link its dependencies too. FreeType is one of the dependencies.

See the list of dependencies for each SFML module here: https://www.sfml-dev.org/faq.php#build-link-static
They are also listed in this tutorial: https://www.sfml-dev.org/tutorials/2.5/start-vc.php

10
For reference, a little bit of documentation was added to the 2.6.x branch about this in pull request #2271.

11
SFML wiki / Re: Get Character At Coord
« on: November 08, 2022, 09:02:55 pm »
That is a nice utility function. I imagine it can be useful to implement a text input field.

I did not test it, but looking at the code, I guess it is not working if the text has some transformation on it, like a 180° rotation for example, or even a maybe more realistic 90° rotation. I am not sure what would be the best way to support that knowing that sf::Text::findCharacterPos returns global coordinates.

Regarding time complexity, note that sf::Text::findCharacterPos has a linear complexity. Your current implementation, by making a linear amount of calls to it, has a quadratic complexity. That might not be noticeable on small enough strings, but using a binary search would probably be better.

12
General / Re: Collision help
« on: August 16, 2014, 11:24:53 am »
Hi,
You are not computing redBlockSprite sides coordinates properly.
For example, if you want to know the left side x coordinate, it is redBlockSprite.getPosition().x (assuming its origin is (0,0)).

Then, when setting position, there are still issues with sides coordinates for the bottom and right cases.
For example, if you want the left side of the characterSprite to be on the right side of the redBlockSprite, you want that :
position.x // character left side
= redBlockSprite.getPosition().x + redBlockSprite.getGlobalBounds().width; // redBlock right side

This kind of formulas are easy to find with a diagram, so take a paper an a pencil, it will be obvious.

13
Feature requests / Re: ability to use rotated images with setTextureRect
« on: August 07, 2014, 12:31:32 pm »
Hi,
In my humble opinion, this feature already exists with sf::VextexArray.
What do you think ? Are you against using it ?

14
Graphics / Re: Problem with stars
« on: August 05, 2014, 03:43:27 pm »
@janszy
Something is wrong in your code: you are using the fill constructor of std::vector and also push_back sprites.
This line
std::vector<sf::Sprite> stars(numStars);
creates a vector of numStars sprites, so there is no need to push back the sprites. Access sprites with stars[index].

By the way, the fill constructor can initialize the sprites with a copy of a given sprite.

What your code could be:
sf::Texture gwiazda;
gwiazda.loadFromFile("gwiazda.png");

int numStars = 5;
std::vector<sf::Sprite> stars(numStars, sf::Sprite(gwiazda));

for(int i=0; i < numStars; ++i)
    stars[i].setPosition(150,i*100);

15
General / Re: String to movement help
« on: August 02, 2014, 11:42:33 am »
Sorry if I was not easily understandable.
I hope this diagram will make it easy.



The distance to travel is calculated on each frame and the player follows the route while this distance is not traveled.

Pages: [1] 2