Reputation: 1128
Im writing a small program in C++ using SFML, execrising myself and getting more comfortable with Sprites, Textures, Texts and stuff.
The problem is, when I click on 1 text(Order), it pops up new window, which has 4 lines:
Order by Remaining Xps
Order by Current Xps
Order by Current Rank
Go Back
My problem is, that while Order by Current Xps shows all sprites normally as it should, Order by Remaining Xps and Order by Current Rank shows icons with wrong sizes.
(I noticed that the Total Level
icon and first icon of the list is always wrong size)
The images:
http://i60.tinypic.com/2n84wmc.png
the list sorted with correct images
http://i58.tinypic.com/2agsp5f.png
as you see, the first icon and the icon next to Total Level
is of wrong size.
The list itself is sorted correctly.
The code is pretty bad, but here are parts that manipulate the sprites and/or textures:
Function for scaling:
void scaleSprite(int pixelsX, int pixelsY, sf::Sprite& sprite)
{
auto tex = sprite.getTexture();
if (!tex) return;
auto texSize = tex->getSize();
auto newTexSize = sf::Vector2u(pixelsX, pixelsY);
auto scaleX = newTexSize.x*1.00f/texSize.x;
auto scaleY = newTexSize.y*1.00f/texSize.y;
sprite.scale(scaleX, scaleY);
}
code that renders the window(all code that doesnt do anything with sprites and textures is ommited, apprart from loading, but loaded textures are all correct)
void showWindowOrdered(std::vector<SkillData>& vec, showOption option, sf::RenderWindow& parent, sf::VideoMode vMode,\
const std::string& name, sf::Uint8 mode)
{
sf::Font font;
font.loadFromFile("fonts/runescape_chat_font.ttf");
std::vector<sf::Texture> texVec;
for(int i = 0; i < 27; ++i)
{
//load the textures
}
enFile.close();
std::vector<sf::Sprite> sprVec;
std::vector<sf::Text> textVec;
for(int i = 0; i < texVec.size(); ++i)
{
sf::Sprite spr;
spr.setTexture(texVec[i]);
scaleSprite(28, 28, spr);
spr.setPosition(1, i*28 + 1);
sprVec.push_back(spr);
sf::Text text;
text.setFont(font);
text.setColor(sf::Color::Yellow);
text.setPosition(35, (i)*(28) + 1);
text.setCharacterSize(25);
textVec.push_back(text);
}
std::vector<sf::Text> textValVec;
for(int i = 0; i < textVec.size(); ++i)
{
//...
}
//...
if (option == showOption::sortXps)
{
//sort for showOption::sortXps
}
else if (option == showOption::sortRank)
{
//sort for showOption::sortRank
}
else
{
//sort for showOption::sortXpsRemaining
}
for(int i = 0; i < sorted.size(); ++i)
{
auto texIndex = findIndexNames(sorted[i].name);
sprVec[i].setTexture(texVec[texIndex]);
sprVec[i].setPosition(1, (i)*28 + 1);
}
//...
sf::RenderWindow window(sf::VideoMode(offset+5, 800), "Sorted by" + s, sf::Style::Close | sf::Style::Titlebar);
while(window.isOpen())
{
auto pos = sf::Mouse::getPosition(window);
sf::Event e;
while(window.pollEvent(e))
{
//...
}
auto bgColor = sf::Color(4, 18, 27);
window.clear(bgColor);
for(auto&& a : textVec)
window.draw(a);
for(auto&& a : textValVec)
{
window.draw(a);
}
for(auto&& a : sprVec)
window.draw(a);
window.draw(goBack);
window.display();
}
}
may the problem be with?
for(int i = 0; i < sorted.size(); ++i)
{
auto texIndex = findIndexNames(sorted[i].name);
sprVec[i].setTexture(texVec[texIndex]);
sprVec[i].setPosition(1, (i)*28 + 1);
}
but without that I cant actually sort the sprite's position, unless manually moving all of them, but the list is not deterministic
Also I tread re-loading the textures before this, rescaling the sprites, it creates the same things or even worse(the first sprite and sprite next to Total Level
are even more weird)
Thank you for your help
Upvotes: 1
Views: 1828