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

Author Topic: SFML 2.0 AABB Class Help  (Read 7129 times)

0 Members and 2 Guests are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 AABB Class Help
« Reply #15 on: January 10, 2014, 03:53:14 pm »
Code: [Select]
min.x = playerTexture.getSize().x;
max.y = playerTexture.getSize().y;

And
Code: [Select]

        min.x = blockTexture.getSize().x;
max.y = blockTexture.getSize().y;


This is correct, isn't it?
Not really... Where are you checking positions? And why is your min depended on the size?
You most likely would want to go with the sprite instead.

        min = playerSprite.getPosition();
        max.x = playerSprite.getGlobalBounds().width;
        max.y = playerSprite.getGlobalBounds().height;

And
        min = blockSprite.getPosition();
        max.x = blockSprite.getGlobalBounds().width;
        max.y = blockSprite.getGlobalBounds().height;

Alternatively you can also use the global bound for the min, just access .top and .left.
« Last Edit: January 10, 2014, 03:55:31 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: SFML 2.0 AABB Class Help
« Reply #16 on: January 10, 2014, 04:56:43 pm »
Code: [Select]
//level.cpp
       
   min.x = blockSprite.getGlobalBounds().left;
   min.y = blockSprite.getGlobalBounds().top;
 
   max.x = blockSprite.getGlobalBounds().width;
   max.y = blockSprite.getGlobalBounds().height;
 
//player.cpp
       
   min.x = playerSprite.getGlobalBounds().left;
   min.y = playerSprite.getGlobalBounds().top;
 
   max.x = playerSprite.getGlobalBounds().width;
   max.y = playerSprite.getGlobalBounds().height;

Now it is always returning true :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: SFML 2.0 AABB Class Help
« Reply #17 on: January 10, 2014, 05:23:16 pm »
Now it is always returning true :(
As this requires very little code to test, could you write an example from ground that can be directly compiled?

Tbh as this is a very simple uni task, shouldn't you be able to solve it on your own with a bit more thinking and debugging? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: SFML 2.0 AABB Class Help
« Reply #18 on: January 10, 2014, 05:26:02 pm »
Just found the issue. I was setting the blockSprite position in my game::init(). Now, for some reason this was creating a block of 600 + 50 instead of 200*50. Moving the setPosition to my default constructor fixed this bug.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Re: SFML 2.0 AABB Class Help
« Reply #19 on: January 10, 2014, 05:31:37 pm »
That's why this

Yes, just add some nice std::cout or set a break point for all the numbers and check them manually.

should have been your first action.

Never trust your code, always make sure it does what it should. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tweezy

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: AW: Re: SFML 2.0 AABB Class Help
« Reply #20 on: January 10, 2014, 05:33:03 pm »
That's why this

Yes, just add some nice std::cout or set a break point for all the numbers and check them manually.

should have been your first action.

Never trust your code, always make sure it does what it should. ;)

Yeah, thanks for the advice! Should be able to sort this now, thanks for your help

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: SFML 2.0 AABB Class Help
« Reply #21 on: January 10, 2014, 05:35:15 pm »
No problem and good luck! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: SFML 2.0 AABB Class Help
« Reply #22 on: January 10, 2014, 05:54:39 pm »
Code: [Select]
min.x = playerTexture.getSize().x;
max.y = playerTexture.getSize().y;

And
Code: [Select]

        min.x = blockTexture.getSize().x;
max.y = blockTexture.getSize().y;


This is correct, isn't it?
Not really... Where are you checking positions? And why is your min depended on the size?
You most likely would want to go with the sprite instead.



        min = playerSprite.getPosition();
        max.x = playerSprite.getGlobalBounds().width;
        max.y = playerSprite.getGlobalBounds().height;

And
        min = blockSprite.getPosition();
        max.x = blockSprite.getGlobalBounds().width;
        max.y = blockSprite.getGlobalBounds().height;

Alternatively you can also use the global bound for the min, just access .top and .left.

You forgot to add position to max, it would be:
        min = playerSprite.getPosition();
                        max = min;       //max = playerSprite.getPosition();
        max.x += playerSprite.getGlobalBounds().width;
        max.y += playerSprite.getGlobalBounds().height;

And
        min = blockSprite.getPosition();
                        max = min;
        max.x += blockSprite.getGlobalBounds().width;
        max.y += blockSprite.getGlobalBounds().height;

 

anything