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
int main() { int i; RenderWindow window(VideoMode(400, 400), "SFML works!");
sf::Shape* shapeArray[3];
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started