C++ Project 2016-2017: Arkanoid
block_sfml.cpp
Go to the documentation of this file.
1 
3 #include "block_sfml.h"
4 
5 #include <SFML/Graphics.hpp>
6 #include <iostream>
7 
8 using namespace std;
9 
10 namespace arkanoidSFML {
11 
12  BlockSFML::BlockSFML(double x, double y, sf::RenderWindow &window, const string &textureFile) : windowSFML(window), transformation(Transformation::getInstance()) {
13 
14  // Set texture
15  if(!texture.loadFromFile(textureFile)) {
16  throw runtime_error("Couldn't load block texture image: " + textureFile);
17  }
18  texture.setSmooth(true);
19  sprite.setTexture(texture);
20 
21  // Set position
22  sprite.setPosition(x, y);
23  setPosition(std::move(transformation->convertVector(sprite.getPosition())));
24 
25  // Set size (width and height) of BlockSFML
26  sf::FloatRect rect = sprite.getLocalBounds();
27  setSize(make_pair(transformation->convertX(rect.width), transformation->convertY(rect.height)));
28  }
29 
31 
33 
34  void BlockSFML::draw() const {
35  windowSFML.draw(sprite);
36  }
37 
38 }
void setSize(pair< double, double > newSize)
Definition: entity.cpp:30
sf::Sprite sprite
The sprite of the BlockSFML.
Definition: block_sfml.h:23
Singleton: This class provides a method to convert screen pixels to their corresponding coordinates i...
All the game gui elements of the Arkanoid game.
Definition: ball_sfml.cpp:10
arkanoid::Vector2D convertVector(const sf::Vector2f &vector)
void setPosition(double x, double y)
Definition: entity.cpp:21