can someone help me fix my animation class? I've created default animation class that's swapping textures of sprite, it works so far, however Ican't move with sprite
Animation.h
#include <string>
#include <SFML\Graphics.hpp>
using namespace sf;
class Animation
{
public:
Animation();
bool Load(std::string, int);
void Swap();
Sprite Draw();
private:
int CurrentImage;
Texture tPlayer[2];
Sprite sPlayer;
};
Animation.cpp
#include "Animation.h"
Animation::Animation()
{
}
void Animation::Swap()
{
if(CurrentImage == 1)
CurrentImage = 0;
else
CurrentImage = 1;
sPlayer.setTexture(tPlayer[CurrentImage]);
}
bool Animation::Load(std::string name, int position)
{
if(tPlayer[position].loadFromFile(name))
{
return true;
}
return false;
}
Sprite Animation::Draw()
{
return sPlayer;
}
Animation.cpp
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <Windows.h>
#include "Animation.h"
using namespace sf;
#pragma comment (lib, "sfml-window.lib")
#pragma comment (lib, "sfml-graphics.lib")
#pragma comment (lib, "sfml-system.lib")
int wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, INT nShowCmd)
{
RenderWindow MainWindow(VideoMode(800, 600), "Lucid Dreaming");
bool left = false, right = false, up = false, down = false;
Texture tBackground;
tBackground.loadFromFile("Background.png");
Sprite sBackground(tBackground);
Animation anim;
anim.Load("Untitled.png", 0);
anim.Load("Untitled2.png", 1);
Sprite spr;
spr = anim.Draw();
while(MainWindow.isOpen())
{
spr = anim.Draw();
Event Event;
while(MainWindow.pollEvent(Event))
{
if(Event.type == Event::Closed)
MainWindow.close();
}
if(Keyboard::isKeyPressed(Keyboard::Left))
{
left = true;
}
if(Keyboard::isKeyPressed(Keyboard::Right))
{
right = true;
}
if(Keyboard::isKeyPressed(Keyboard::Up))
{
up = true;
}
if(Keyboard::isKeyPressed(Keyboard::Down))
{
down = true;
}
if(left)
spr.move(-0.1f, 0);
if(right)
spr.move(0.1f, 0);
if(up)
spr.move(0, -0.1f);
if(down)
spr.move(0, 0.1f);
left = false;
right = false;
up = false;
down = false;
MainWindow.clear();
MainWindow.draw(sBackground);
anim.Swap();
MainWindow.draw(spr);
MainWindow.display();
}
return 0;
}