Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

LO4 List options for development needs analyses.

Answered: 1 week ago