Hi!
I'm having a hard time figuring out this...
I have a class for world boundries:
// RUUTU_W = 800
// RUUTU_H = 450
MaailmanRajat::MaailmanRajat():
rectUp_(0, -5, RUUTU_W, 0), rectDown_(0, RUUTU_H, RUUTU_W, RUUTU_H+5), rectLeft_(-5, 0, 0, RUUTU_H),
rectRight_(RUUTU_W, 0, RUUTU_W+5, RUUTU_H)
{
}
bool MaailmanRajat::TormasiSeinaan(sf::FloatRect hitbox)
{
if (hitbox.Intersects(rectUp_))
{
return true;
}
if (hitbox.Intersects(rectDown_))
{
return true;
}
if (hitbox.Intersects(rectLeft_))
{
return true;
}
if (hitbox.Intersects(rectRight_))
{
return true;
}
return false;
}
And I have a Player class where I'm checking if the player is out of world boundries (this should be changed to "the player will not be able to move outside boundries, but that's not the issue right now").
// Can the player move?
bool Pelaaja::pystyykoLiikkumaan(FKoordinaatti paamaara, sf::RenderWindow& App)
{
sf::Vector2f A;
sf::Vector2f B;
A.x = 0;
A.y = 0;
B.x = sprite_.GetSize().x;
B.y = sprite_.GetSize().y;
A = sprite_.TransformToGlobal(A);
B = sprite_.TransformToGlobal(B);
sf::FloatRect rect(A.x, A.y, B.x, B.y);
// MaailmanRajat* rajat_;
return !(rajat_->TormasiSeinaan(rect));
}
Player class also has this at its constructor:
sprite_.SetCenter( (kuva_.GetWidth()/2), (kuva_.GetHeight()/2) );
But this doesn't work. Only the upper border works in some way but still in seemingly random way.