Hello, everybody :]
Is it possible to make a pointer to an sf::Shape::Rectangle object? I know it's a static function, but I'm not altogether familiar with static functions to know what can and cannot be done with them.... I just know that you can access their data without one being instantiated.
My idea was to create a pointer to a single Rectangle (which is to be 1 x 1 in size so as to emulate drawing a pixel) and then point to it using a pointer in the Draw function in my program to randomly redraw it a bunch of times on the screen. What I have as my original idea is this, without pointers:
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
int main()
{
// Create main window
sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics",
sf::Style::Fullscreen);
int pointCounter = 0;
int randX, randY;
sf::Clock pointTimer;
App.Clear();
pointTimer.Reset();
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
randX = sf::Randomizer::Random(0, 640);
randY = sf::Randomizer::Random(0, 480);
App.Draw(sf::Shape::Rectangle(randX, randY, randX + 1, randY + 1,
sf::Color(sf::Randomizer::Random(0, 255),
sf::Randomizer::Random(0, 255),
sf::Randomizer::Random(0, 255))));
pointCounter += 1;
if (pointTimer.GetElapsedTime() >= 10)
{
cout << "Points Drawn 10 Sec: " << pointCounter << endl;
return EXIT_SUCCESS;
}
// Finally, display the rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}
It lets you see how many of the Rectangles were drawn through the console in 10 seconds, and I'm at about 23,000 while in fullscreen and 12,000 in windowed mode. It was my hope that I could increase this number using a pointer to a single Rectangle and then refer to it and adjust its properties every iteration instead of drawing a brand new one. Any thoughts or possible suggestions, or any information as to whether this idea is even plausible to begin with? :] Thank you all very much!
Colton