简体   繁体   中英

can't draw an SFML sprite when sprite has a negative position

Whenever I try to draw an SFML sprite with a negative position, the sprite will not be drawn to the screen. I have tried with and without a view applied to the window, but the sprite is not rendered either time.

I have a sprite with a texture on it (size 32*64). I try drawing in at position (-1,-1) but it will not work. Is this intentional behaviour. If so how would I go about drawing sprites with negative positions. thanks

sf::Texture texture;
if (!texture.loadFromFile("texture.png")) {
    std::cout << "Error rendering Object";
    return 0;
}

sf::Sprite Sprite;
Sprite.setTexture(texture);

Sprite.setPosition(sf::Vector2f(-5, -5));

And draw sprite > window.draw(Sprite);

Turns out that I had some confusing mix-ups with signed and unsigned ints. This caused the sprites to be unable to be drawn in negative positions. Please check signed-unsigned types if this error occured for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM