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

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

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

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

5
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

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

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

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

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

10
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);

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

12
General / Re: String to movement help
« on: August 01, 2014, 02:18:40 pm »
Quote
while(toTravel > 0.f && !route.empty())
Shouldn't this be a "if" rather than a "while"? ;)

No, it is a "while".
The player movement can be split into several parts in one frame: if the player is close enough to the m_nextPosition at the beginning of the frame or if the distance to travel is big enough (long frameTime or high speed).

13
General / Re: String to movement help
« on: August 01, 2014, 11:35:46 am »
Hello,
What you can do is to compute the next position from your route and go towards this position on each frame.

(click to show/hide)

14
Window / Re: Change viewport to keep aspect ratio of scene
« on: August 01, 2014, 10:45:01 am »
Here is how I would do it.
I hope it helps.

sf::View calcView(const sf::Vector2f& windowSize, float minRatio, float maxRatio)
{
    sf::Vector2f viewSize = windowSize;

    // clip ratio
    float ratio = viewSize.x / viewSize.y;
    if(ratio < minRatio) // too high
        viewSize.y = viewSize.x / minRatio;
    else if(ratio > maxRatio) // too wide
        viewSize.x = viewSize.y * maxRatio;

    sf::View view(sf::FloatRect(sf::Vector2f(), viewSize));

    sf::FloatRect viewport((windowSize - viewSize) / 2.f, viewSize);
    viewport.left /= windowSize.x;
    viewport.top /= windowSize.y;
    viewport.width /= windowSize.x;
    viewport.height /= windowSize.y;
    view.setViewport(viewport);

    return view;
}

15
Audio / Re: Trouble loading audio from memory.
« on: March 05, 2014, 07:50:55 pm »
Hello,

In your getMusic function,
Quote
if(musicBuffer[i])
{
    /* initialize */
}

Didn't you mean this ?
if(!musicBuffer[i])
(notice the negation '!')

Pages: [1] 2