1
General / Re: Linking Error
« on: July 06, 2013, 06:31:31 pm »
Thank you, Laurent! I've completely forgotten that I have copied SFML/include into Visual Studio/include folder. Problem solved
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>
#define TEXTURE_WIDTH 1200
#define TEXTTURE_HEIGHT 798
#define PI 3.141592654
#define SPEED 111
int main()
{
sf::VideoMode dm = sf::VideoMode::GetDesktopMode();
sf::RenderWindow App(dm, "SFML Views", sf::Style::Fullscreen);
App.EnableVerticalSync(true);
App.SetFramerateLimit(60);
sf::Image BackgroundImage;
if (!BackgroundImage.LoadFromFile("Grass.jpg" )) //http://www.dizayner.ucoz.com/3ddd/3dmitri/Grass_from_cg_textures.jpg
return 1;
sf::Sprite Background(BackgroundImage);
Background.Resize(TEXTURE_WIDTH , TEXTTURE_HEIGHT);
sf::Vector2f Center(1000, 1000); //init position
sf::Vector2f HalfSize(dm.Width / 2, dm.Height/ 2);
sf::View View(Center, HalfSize);
float angle = 45; // init camera angle
sf::Vector2f position;
position.x = Background.GetPosition().x + Background.GetSize().x / 2;
position.y = Background.GetPosition().y + Background.GetSize().y / 2;
while (App.IsOpened())
{
float time = App.GetFrameTime();
sf::Event Event;
while (App.GetEvent(Event))
{
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
//flickering
//position.x += SPEED * time * cos((angle - 90) * 2 * PI / 360);
//position.y += SPEED * time * sin((angle - 90) * 2 * PI / 360);
//no flickering
const float MYSPEED = 3; // depends on your hardware
position.x += MYSPEED * cos((angle - 90) * 2 * PI / 360);
position.y += MYSPEED * sin((angle - 90) * 2 * PI / 360);
if (App.GetInput().IsKeyDown(sf::Key::Left)) angle -= 1.5f;
if (App.GetInput().IsKeyDown(sf::Key::Right)) angle += 1.5f;
View.SetCenter(position.x, position.y);
View.SetRotation(angle);
App.SetView(View);
App.Clear();
for(int w = 0; w < 5; w++)
for(int j = 0; j < 5; j++)
{
Background.SetPosition(TEXTURE_WIDTH * w, TEXTTURE_HEIGHT * j);
App.Draw(Background);
}
App.Display();
}
return 0;
}