Reputation: 41
Hi I am trying to set up a program where a ball will bounce across the renderwindow. I am using SFML c++, iostream, codeblocks(if that makes a difference). I know that I am not anywhere near completion and I may very well be going in the wrong direction. However, one thing I do know for certain is that in order for my program to work I will need to implement sf::Window::setFramerateLimit(60);Or at least that is what I have in my code.
include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
using namespace sf;
int main(){
RenderWindow window(sf::VideoMode(1500,800), "Bouncing Circle");
sf::Window::setFramerateLimit(60);
When ever I try to build/run my program I get an error:
error: cannot call member function 'void sf::Window::setFramerateLimit(unsigned int)' without object|
#include<iostream>
#include<SFML/Graphics.hpp>
#include<stdlib.h>
#include<time.h>
using namespace std;
using namespace sf;
int main(){
RenderWindow window(sf::VideoMode(1500,800), "Bouncing Circle");
sf::Window::setFramerateLimit(60);
srand(time(NULL));
int Rand1 = rand()%1500+1;
int Rand2 = rand()%800+1;
int x;
int y;
int BREAK = 1;
sf::CircleShape MyCircle(50);
MyCircle.setPosition(1,1);
MyCircle.setFillColor(sf::Color(500,0,0));
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event));
{
if(event.type == sf::Event::Closed)
window.close();
}
x = 1;
y = 1;
for(int ii = 0; ii < 675; ii++){
x++;
y++;
MyCircle.setPosition(x, y);
window.draw(MyCircle);
window.display();
window.clear();
BREAK++;
if(BREAK == 675){
break;
}
}
}
return 0;
}
Upvotes: 0
Views: 146
Reputation: 66
sf::Window::setFramerateLimit(unsigned int); is not a static member function. So you will to have an instance to call it. In a nutshell :
int main()
{
sf::RenderWindow win(sf::VideoMode(500, 500), "Title");
win.setFramerateLimit(60);
return 0;
}
SFML Documentation warn us about using this function and vsync !
Upvotes: 0
Reputation: 46
Where you have sf::Window::setFramerateLimit(60);
try instead window.setFramerateLimit(60);
this sets the framerate for your created window (named "window") to 60 frames per second.
Upvotes: 1