1
General discussions / Re: SFML Game Development -- A book on SFML
« on: September 03, 2013, 04:35:34 am »
Just bought the book, I am excited to see what I can learn from it. Always amazed by the support SFML has.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(600, 400), "View");
window.setFramerateLimit(60);
sf::CircleShape circle;
circle.setFillColor(sf::Color::Black);
circle.setRadius(15);
sf::View view = window.getView();
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
if( event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left )
{
circle.setPosition(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A))
view.move(-5.f, 0.f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D))
view.move(5.f, 0.f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W))
view.move(0.f, -5.f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S))
view.move(0.f, 5.f);
window.clear(sf::Color::White);
window.setView(view);
window.draw(circle);
window.display();
}
return 0;
}
Lock::Lock(Mutex& mutex) :
myMutex(mutex)
{
myMutex.Lock();
}
//example.hpp
#ifndef EXAMPLE_HPP_
#define EXAMPLE_HPP_
#include <SFML\Graphics.hpp>
class Example
{
static sf::Image image;
static sf::Sprite sprite;
};
#endif
//example.cpp
#include "example.hpp"
sf::Image Example::image;
sf::Sprite Example::sprite;
//main.cpp
#include <iostream>
int main()
{
}
myMutex(mutex)
{
myMutex.Lock();
}