Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw a sprite at the bottom of screen, using its own size  (Read 1654 times)

0 Members and 1 Guest are viewing this topic.

de5cartes

  • Newbie
  • *
  • Posts: 9
    • View Profile
Draw a sprite at the bottom of screen, using its own size
« 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 ?


KRS

  • Newbie
  • *
  • Posts: 19
  • The burning you feel?
    • View Profile
    • Email
Re: Draw a sprite at the bottom of screen, using its own size
« Reply #1 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);

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Draw a sprite at the bottom of screen, using its own size
« Reply #2 on: March 20, 2021, 01:26:10 am »
are you sure you're not using getLocalBounds instead of getGlobalBounds in your code??
Visit my game site (and hopefully help funding it? )
Website | IndieDB