Hello, I'm trying to create a rect, that is the same size as a shape and I've been having trouble.
Here's my code.
int main()
{
//declare variables
bool Falling;
Falling = true;
// Create the main window
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
const sf::Input& Input = App.GetInput();
// Load a sprite to display
sf::Shape Player = sf::Shape::Rectangle(50,50,100,100,sf::Color::White);
Player.SetPosition(200,200);
sf::Shape CollisionTest = sf::Shape::Rectangle(50,50,150,150,sf::Color::Cyan);
CollisionTest.SetPosition(200,400);
// Start the game loop
while (App.IsOpened())
{
//timer
float Time = Clock.GetElapsedTime();
Clock.Reset();
//Rectangles for Collision Detection
sf::IntRect ghostRect;
ghostRect.Left = Player.GetPosition().x;
ghostRect.Top = Player.GetPosition().y;
ghostRect.Right = Player.GetScale().x;
ghostRect.Bottom = Player.GetScale().y;
sf::IntRect TestRect;
TestRect.Left = CollisionTest.GetPosition().x;
TestRect.Top = CollisionTest.GetPosition().y;
TestRect.Right = CollisionTest.GetScale().x;
TestRect.Bottom = CollisionTest.GetScale().y;
//Handles various If statements such as falling,input, and collision
if(Falling == true)
{
Player.Move(0,100*Time);
}
if(App.GetInput().IsKeyDown(sf::Key::A))
{
Player.Move(-100 * Time,0);
}
if(App.GetInput().IsKeyDown(sf::Key::D))
{
Player.Move(100 * Time,0);
}
if(App.GetInput().IsKeyDown(sf::Key::Left))
{
Player.Move(-100 * Time,0);
}
if(App.GetInput().IsKeyDown(sf::Key::Right))
{
Player.Move(100 * Time,0);
}
if(ghostRect.Intersects(TestRect))
{
break;
}
}
Some code has been taken out because it has nothing to do with the Rectangle problem.