Susan Yanders
Susan Yanders

Reputation: 874

C++ SFML - Render at Specific Coordinates

I wanted to have my own game rendering style, but I want to know how to render a sprite at specific coordinates in SFML. I know you can do things like sprite.setPositon(20, 56) but I want to do it more like window.drawAt(mySprite, 20, 56), because that would be a lot easier.

Upvotes: 0

Views: 128

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103713

Make a function that takes a window and a sprite by reference.

void drawAt(sf::RenderWindow & window, sf::Sprite & mySprite, int x, int y)
{
    // set sprite position, then draw it
}

Then you can call it like this:

drawAt(window, mySprite, 20, 56);

Which is just as easy as this:

window.drawAt(mySprite, 20, 56);

Upvotes: 2

Related Questions