Witam, mam problem z rysowaniem obiektów z vectora, nie wiem z jakiego powodu nie są one rysowane w oknie, prosiłbym o radę oraz ewentualne wskazanie błędów lub poprawę schematu kodu
Block.h
#include <SFML/Graphics.hpp>
using namespace sf;
class Block : public Drawable
{
private:
int block_width=40;
int block_heigth=80;
RectangleShape shape;
Vector2f bok = { block_width,block_heigth };
public:
RectangleShape getShape();
Block(float px, float py);
Block()=delete;
~Block()=default;
void draw(RenderTarget &target, RenderStates state) const override;
};
Block.cpp
#include "Block.h"
Block::Block(float px, float py)
{
this->shape.setPosition(px, py);
this->shape.setFillColor(Color::Yellow);
this->shape.setSize(bok);
this->shape.setOrigin(block_width / 2.0f, block_heigth / 2.0f);
}
void Block::draw(RenderTarget &target, RenderStates state) const
{
target.draw(this->shape, state);
}
RectangleShape Block::getShape()
{
return this->shape;
}
Engine.cpp
#include "Engine.h"
Engine::Engine()
{
Vector2f resolution;
resolution.x = VideoMode::getDesktopMode().width;
resolution.y = VideoMode::getDesktopMode().height;
window.create(VideoMode(resolution.x, resolution.y),
"Game Engine", Style::Fullscreen);
backgroundTexture.loadFromFile("background.jpg");
backgroundSprite.setTexture(backgroundTexture);
}
Engine::~Engine()
{
}
void Engine::createBlocks(int ilosc, vector<Block> vec)
{
int n1 = 200, n2 = 200;
for (int i = 0; i < ilosc; i++)
{
Block block(n1, n2);
vec.push_back(block);
n1 += 200;
}
}
void Engine::input()
{
if (Keyboard::isKeyPressed(Keyboard::Escape))
{
window.close();
}
}
void Engine::start()
{
Clock clock;
vector<Block>::iterator it;
vector<Block>::iterator end;
while (window.isOpen())
{
createBlocks(10, vecBlock);
// Restart the clock and save the elapsed time into dt
Time dt = clock.restart();
// Make a fraction from the delta time
float dtAsSeconds = dt.asSeconds();
window.draw(ball);
window.draw(paddle);
window.draw(bloczek);
for (it = vecBlock.begin(), end = vecBlock.end(); it != end; it++)
{
window.draw(it->getShape());
}
window.display();
window.clear();
ball.update();
ball.update2(paddle);
paddle.update();
input();
}
}