Hello, here is my code. Im trying to write the programm which puts circleshapes on cursor position. I must use dynamic arrays. Could you say me, whats wrong and why my programm doesnt work? Thank you very much
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace sf;
using namespace std;
RenderWindow app;
class CS
{
public:
CircleShape *items;
int size;
void Add() {
size++;
CircleShape *newArray = new CircleShape(size);
for (int i = 0; i < size - 1; i++)
newArray[i] = items[i];
items = newArray;
items[size - 1].setFillColor(Color::Blue);
items[size - 1].setRadius(20);
}
};
CS circleShape;
int main()
{
float xResolution = VideoMode::getDesktopMode().width;
float yResolution = VideoMode::getDesktopMode().height;
app.create(VideoMode(xResolution, yResolution), "1", Style::Fullscreen);
while (true)
{
app.clear(Color::White);
if (Keyboard::isKeyPressed(sf::Keyboard::D))
{
circleShape.Add();
int mouseX = Mouse::getPosition().x, mouseY = Mouse::getPosition().y;
circleShape.items[circleShape.size - 1].setPosition(mouseX, mouseY);
for (int i = 0; i < circleShape.size; i++)
app.draw(circleShape.items[i]);
}
app.display();
}
return 0;
}