// SFMLgame.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include "Ball.h"
using namespace sf;
using namespace std;
int main()
{
RenderWindow window{ VideoMode{500,500} ,"Game SFML" };
window.setFramerateLimit(60);
Event event;
Ball ball(400,300);
while (true) //główna pętla gry
{
window.clear(Color::Black);
window.pollEvent(event); //czeka na zdarzenie i wykonuje wszystkie funkcjie wewnątrz
if(event.type==Event::Closed) //zamykanie okna
{
window.close();
break;
}
window.draw(ball);
window.display();
}
return 0;
}
-----------------------------------------------------------------
#pragma once
#include<SFML\Graphics.hpp>
using namespace sf;
class Ball : public sf::Drawable //mozliwosc rysowania
{
public:
Ball(float bX, float bY);
Ball()=delete;
~Ball()=default;
private:
CircleShape shape;
const float ballRadius{ 10.0f };
void draw(RenderTarget& target, RenderStates state) const override;
};
---------------------------------------------------------------------
#include "stdafx.h"
#include "Ball.h"
Ball::Ball(float bX,float bY)
{
shape.setPosition(bX, bY);
shape.setRadius(this->ballRadius);
shape.setFillColor(Color::White);
shape.setOrigin(this->ballRadius, this->ballRadius);
}
void Ball::draw(RenderTarget& target, RenderStates state)const
{
target.draw(this->shape, state);
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}