1
Graphics / Simulating Window-Border Collision!
« on: August 05, 2011, 11:17:53 pm »
Edited:
Hmm, couldn't convert from sf::sprite to sf::shape, so I replaced the function parameter with sf::sprite instead, and removed the ampersand sign.
My sprite effectively stops at the border... But then becomes unresponsive
Did i change too much?
Hmm, couldn't convert from sf::sprite to sf::shape, so I replaced the function parameter with sf::sprite instead, and removed the ampersand sign.
My sprite effectively stops at the border... But then becomes unresponsive
Did i change too much?
Code: [Select]
//the function
bool locationAllowed(sf::Sprite sprite) {
sf::Vector2f temp = sprite.GetPosition();
int x = temp.x + 1;
int y = temp.y + 1;
if (x > 800 || x < 0) {
return false;
}
if (y > 600 || y < 0) {
return false;
}
return true;
}
Code: [Select]
if (LeftKeyDown && locationAllowed(Blob))
Blob.Move(-KeyMove, 0);
if (RightKeyDown && locationAllowed(Blob))
Blob.Move(KeyMove, 0);
if (UpKeyDown && locationAllowed(Blob))
Blob.Move(0, -KeyMove);
if (DownKeyDown && locationAllowed(Blob))
Blob.Move(0, KeyMove);
if (GKeyDown && locationAllowed(Blob))
Blob.Rotate(KeyMove);
if (HKeyDown && locationAllowed(Blob))
Blob.Rotate(-KeyMove);