Question: How do I create multiple objects of the same shape when I am using arrays? (ex: circles or rectangles) My code so far: #include #include

How do I create multiple objects of the same shape when I am using arrays? (ex: circles or rectangles)

My code so far:

#include #include using namespace sf;

int main() { int i; RenderWindow window(VideoMode(400, 400), "SFML works!");

sf::Shape* shapeArray[3];

setRadius(10); cPtr->setOutlineColor(sf::Color::White); cPtr->setOutlineThickness(5); cPtr->setPosition(20, 175); shapeArray[0] = cPtr;

sf::CircleShape*(1) cPtr = new sf::CircleShape; cPtr->setRadius(10); cPtr->setOutlineColor(sf::Color::White); cPtr->setOutlineThickness(5); cPtr->setPosition(20, 200); shapeArray[1] = cPtr;

sf::RectangleShape* rPtr = new sf::RectangleShape; rPtr->setSize(sf::Vector2f(100, 50)); rPtr->setOutlineColor(sf::Color::Green); rPtr->setOutlineThickness(5); rPtr->setPosition(10, 20); shapeArray[2] = rPtr;

while (window.isOpen()) { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); }

window.clear(); for(i = 0; i < 3; i++) { window.draw(*shapeArray[i]); } window.display(); }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!