SFML community forums

Help => Graphics => Topic started by: de5cartes on March 02, 2021, 10:03:18 pm

Title: Draw a sprite at the bottom of screen, using its own size
Post by: de5cartes on March 02, 2021, 10:03:18 pm
Hi guys

This is whats happening:
1. I have a spritesheet image with some textures from various elements.
2. I created a sprite based on a this spritesheet, defining the texture rect.
3. I also resized the sprite down according by ratio of the screen width.

The sprite is drawn perfectally, no problems there.

Now I want to align the sprite to the bottom of the screen,so I set its position like this:
midGroupSky2Sprite.setPosition(1, window.getSize().y -midGroupSky2Sprite.getGlobalBounds().height);

The result makes part of the sprite go offscreen at the bottom and not perfectally aligned.

I then tried this:
midGroupSky2Sprite.setPosition(1, window.getSize().y - midGroupSky2Sprite.getTextureRect().height);

The sprite is now too high.

What am I doing wrong ?

Title: Re: Draw a sprite at the bottom of screen, using its own size
Post by: KRS on March 19, 2021, 09:44:32 pm
Hello! Not really understand the problem, maybe you can provide a picture?
Also, did you tried this? It should allign upper left point of the sprite with apper left angle of the screen, exactly what you need if I'm not wrong.
midGroupSky2Sprite.setPosition(0, 0);
Title: Re: Draw a sprite at the bottom of screen, using its own size
Post by: Stauricus on March 20, 2021, 01:26:10 am
are you sure you're not using getLocalBounds instead of getGlobalBounds in your code??