Hey guys,
I'm trying to program a very basic avoider type game just to kind of remind myself of some coding topics, and my skills are proving rustier than I imagined. One of the issues i'm having is with collision detection and getGlobalBounds(). I'm trying to use the bounds of a member object (in this case text) as the bounds of the classes i have made. I can't get that to work at all, and can't seem to figure it out.
I have a class that looks like this(please be gentle, I haven't coded something like this in YEARS):
class Enemy : public sf::Sprite
{
public:
Enemy();
~Enemy();
sf::FloatRect getMemberBounds();
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
sf::Font enemyFont; //the enemies are letters for now
sf::Text enemyText;
};
Enemy::Enemy()
{
//text setup that i *think* has no effect on the collision box goes here
setPosition(500, 500);
enemyText.setPosition(getPosition());
}
Enemy::getMemberBounds()
{
return enemyText.getGlobalBounds();//use text bounds as enemy bounds
}
Enemy::draw(sf::RenderTarget&, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(enemyText);
}
and then I have a Playable class for the player controlled character which is setup in very much the same way. I realize that my method getMemberBounds() is probably a horrible way to go about this, and might be the source of my issue. but what I want to be able to do is this:
if(character.getMemberBounds().intersects(enemy.getMemberBounds()))
{
//near phase collision detection calls
}
I'm kind of at a loss for tweaks/changes to try. so any suggestions/critiques/tips are more than welcome. and if i haven't given enough information, I will edit and add w/e i need to.
thanks!