Skip to content

Instantly share code, notes, and snippets.

@kirbyUK
Created October 10, 2014 17:12
Show Gist options
  • Save kirbyUK/38ffc6c80acb58050f8b to your computer and use it in GitHub Desktop.
Save kirbyUK/38ffc6c80acb58050f8b to your computer and use it in GitHub Desktop.
SFML Utilities Header
/*
* sfUtil.h
* A simple, header only file (so you don't have to edit any Makefiles) used
* for common SFML debugging tasks.
*/
#ifndef SF_UTIL_H
#define SF_UTIL_H
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
namespace sf
{
namespace Util
{
//Prints the position of a given sprite, shape or text item:
void printPos(sf::Transformable t, std::string label="")
{
std::cout << std::fixed
<< label
<< " ("
<< t.getPosition().x
<< ", "
<< t.getPosition().y
<< ")\n";
}
//Takes an sf::Rect and returns an sf::RectangleShape
//(useful for drawing hiboxes):
sf::RectangleShape rectToShape(sf::FloatRect rect,
sf::Color outline = sf::Color::Red)
{
sf::RectangleShape r(sf::Vector2f(rect.width, rect.height));
r.setPosition(rect.left, rect.top);
r.setOutlineThickness(1);
r.setFillColor(sf::Color::Transparent);
r.setOutlineColor(outline);
return r;
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment