#include <SFML/Graphics.hpp>
class Player
{
public:
int health;
int attackDamage;
int friendshipMeter;
int Move();
sf::Sprite SpritePlayer;
sf::Image ImagePlayer;
sf::RenderWindow App;
sf::Sprite Initialize()
{
ImagePlayer.LoadFromFile("squiddlePlayer.png");
SpritePlayer.SetImage(ImagePlayer);
return SpritePlayer;
}
void Update(sf::RenderWindow App)
{
float ElapsedTime = App.GetFrameTime();
// Move the sprite
if (App.GetInput().IsKeyDown(sf::Key::Left)) SpritePlayer.Move(-100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Right)) SpritePlayer.Move( 100 * ElapsedTime, 0);
if (App.GetInput().IsKeyDown(sf::Key::Up)) SpritePlayer.Move(0, -100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Down)) SpritePlayer.Move(0, 100 * ElapsedTime);
// Rotate the sprite
if (App.GetInput().IsKeyDown(sf::Key::Add)) SpritePlayer.Rotate(-100 * ElapsedTime);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) SpritePlayer.Rotate( 100 * ElapsedTime);
}
};
#include "Player.h"
#include <SFML/Graphics.hpp>
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "The Day the Unicorns Couldn't Play");
Player Player;
sf::Sprite spritePlayer = Player.Initialize();
// Start game loop
while (App.IsOpened())
{
Player.Update(App);
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Clear the screen (fill it with black color)
App.Clear();
App.Draw(spritePlayer);
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
Those are my two files, Main.cpp and Player.h. When I have the Player.Update(App) line in, the code doesn't compile. But it appears to be a error with the default code:
error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
c:\program files\sfml\sfml-1.6\include\sfml\system\noncopyable.hpp(57) : see declaration of 'sf::NonCopyable::NonCopyable'
c:\program files\sfml\sfml-1.6\include\sfml\system\noncopyable.hpp(41) : see declaration of 'sf::NonCopyable'
This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
I don't understand why simply calling a function could call this error. Unless I can't use the RenderWindow as a argument? If I can't, then what can I do to have an update function?