예제 #1
0
void click(sf::RectangleShape rectangle,sf::Sprite &sprite, bool &clicked, bool &player, sf::Texture &crossTexture, sf::Texture &circleTexture, sf::Event &event) {
	if (((rectangle.getPosition().x <= event.mouseButton.x && event.mouseButton.x <= rectangle.getLocalBounds().width + rectangle.getPosition().x) &&
		(rectangle.getPosition().y <= event.mouseButton.y && event.mouseButton.y <= rectangle.getLocalBounds().height + rectangle.getPosition().y)) &&
		!(clicked)) {
		std::cout << "You clicked on a rectangle" << std::endl;
		clicked = true;
		if (player) {
			std::cout << "cross" << std::endl;
			sprite.setTexture(crossTexture);
		} else {
			std::cout << "circle" << std::endl;
			sprite.setTexture(circleTexture);
		}
		player = !player;
	}
}
예제 #2
0
void MameUIsenWindow::centerElement(sf::RectangleShape& rectangleShape)
{
	sf::FloatRect fr = rectangleShape.getLocalBounds();
	rectangleShape.setOrigin(fr.left + fr.width/2.0f, fr.top + fr.height/2.0f);
}
void centerOrigin(sf::RectangleShape& shape)
{
    sf::FloatRect bounds = shape.getLocalBounds();
    shape.setOrigin(std::floor(bounds.left + bounds.width/2.f), std::floor(bounds.top + bounds.height/2.f));
}
예제 #4
0
void centerTextPosition( const sf::RectangleShape& rect, sf::Text& text )
{
	text.setPosition( rect.getPosition().x + ( rect.getLocalBounds().width / 2 ), rect.getPosition().y + ( rect.getLocalBounds().height / 2 ) - ( text.getCharacterSize() / 2 ) );
}