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
Graphics / Re: Sprite doesn't display
« on: May 10, 2025, 01:30:09 am »
This is probably because the texture is after the sprite in your Heart type. It implies the texture is initialized after the sprite, regardless of the texture being before the sprite in Heart constructor's initializer list. So you are initializing the sprite with a texture not yet initialized. The sprite constructor internally queries the texture size, which is an undefined behavior on an uninitialized texture.

To fix it, you could move the texture before the sprite in Heart type.

But even then, storing the texture referenced by the sprite in the same structure is a bad idea. It creates potential lifetime issues.
Consider the following pseudo-code:
Heart h1{player, position}; // h1.sprite references h1.texture
{
    Heart h2{player, position};
    h1 = h2; // h1.sprite now references h2.texture
} // h2 is destroyed
// h1.sprite references a texture that does not exist anymore -> bug

In addition, copying the texture in each Heart instance is unnecessary.
You could simply have a single texture instance, which is heart_sprite apparently in your code, and use it to initialize your sprites. This would solve both the initialization order issue and lifetime issue.

2
General / Re: qualified-id in declaration before ‘event’
« on: April 29, 2025, 10:16:38 pm »
What version of SFML did you install?
It looks like you are trying to use SFML 3 while having SFML 2.6 or earlier installed.

Once you install SFML 3, then you would also need to tell the compiler to use C++17 or higher, adding -std=c++17 to your compilation command line.
Eventually, you can setup a CMake project to take care of this detail.

3
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.

4
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

5
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.

6
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

7
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).

8
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);
}

9
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).

10
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.

11
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

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

13
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.

14
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.

15
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 ?

Pages: [1] 2
anything