Whenever I try to build my project in Xcode, the app appears on the dock but it just bounces forever. I don't have any errors or anything. Also, the template worked and I could run that just fine.
Here is my code if it matters:
//
// Disclamer:
// ----------
//
// This code will work only if you selected window, graphics and audio.
//
// Note that the "Run Script" build phase will copy the required frameworks
// or dylibs to your application bundle so you can execute it on any OS X
// computer.
//
// Your resource files (images, sounds, fonts, ...) are also copied to your
// application bundle. To get the path to these resource, use the helper
// method resourcePath() from ResourcePath.hpp
//
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
// Here is a small helper for you ! Have a look.
#include "ResourcePath.hpp"
void initShape(sf::RectangleShape& shape, sf::Vector2f const& pos, sf::Color const& color)
{
shape.setFillColor(color);
shape.setPosition(pos);
shape.setOrigin(shape.getSize() * 0.5f);
}
int main()
{
sf::RenderWindow window(sf::VideoMode(480, 380), "Bad Squares");
window.setFramerateLimit(60); //set the frame limit to 60 FPS
sf::Image icon;
if (!icon.loadFromFile(resourcePath() + "icon.png")) {
return EXIT_FAILURE;
}
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
sf::Vector2f startPosition = sf::Vector2f(50, 50);
sf::RectangleShape playerSquare(sf::Vector2f(25, 25));
initShape(playerSquare, startPosition, sf::Color::Yellow);
sf::RectangleShape targetSquare(sf::Vector2f(50, 50));
initShape(targetSquare, sf::Vector2f(400, 50), sf::Color::Green);
sf::RectangleShape badSquareOne(sf::Vector2f(50, 100));
initShape(badSquareOne, sf::Vector2f(250, 50), sf::Color::Red);
sf::RectangleShape badSquareTwo(sf::Vector2f(50, 200));
initShape(badSquareTwo, sf::Vector2f(250, 250), sf::Color::Red);
sf::RectangleShape changeToRedZoneOne(sf::Vector2f(425, 75));
initShape(changeToRedZoneOne, sf::Vector2f(400, 50), sf::Color::Yellow);
window.clear(sf::Color::Black);
while (window.isOpen())
{
window.draw(targetSquare);
window.draw(badSquareOne);
window.draw(badSquareTwo);
window.draw(playerSquare);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down))
{
window.clear(sf::Color::Black);
playerSquare.move(0, 2);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up))
{
window.clear(sf::Color::Black);
playerSquare.move(0, -2);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left))
{
window.clear(sf::Color::Black);
playerSquare.move(-2, 0);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right))
{
window.clear(sf::Color::Black);
playerSquare.move(2, 0);
}
if (playerSquare.getGlobalBounds().intersects(targetSquare.getGlobalBounds()))
{
window.clear(sf::Color::Red);
}
if (playerSquare.getGlobalBounds().intersects(badSquareOne.getGlobalBounds()))
{
window.clear(sf::Color::Red);
}
if (playerSquare.getGlobalBounds().intersects(changeToRedZoneOne.getGlobalBounds()))
{
targetSquare.setFillColor(sf::Color::Red);
}
badSquareTwo.rotate(2);
window.clear(sf::Color::Black);
window.display();
}
return EXIT_SUCCESS;
}