No, I don't do everything on the one line, the issue I have is that when I hit another key, it doesn't change the sprites texture. This is the part of the script that controls the player and movement
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Lester.h"
sf::Texture tp_sprite_l, tp_sprite_r, tp_sprite_d, tp_sprite;
sf::Sprite p_sprite, p_sprite_l, p_sprite_r, p_sprite_d;
void Lester::PlayerSetup()
{
tp_sprite_l.loadFromFile("data/assets/player/left_char.png");
tp_sprite_r.loadFromFile("data/assets/player/right_char.png");
tp_sprite_d.loadFromFile("data/assets/player/down_char.png");
tp_sprite.loadFromFile("data/assets/player/up_char.png");
p_sprite.setTexture(tp_sprite);//Set Texture
window->draw(p_sprite);
}
void Lester::KeyInput()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Q)){ window->close(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) p_sprite.move(-4, 0); m_view->move(-4, 0); std::cout << "LEFT" << std::endl;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)){ p_sprite.move(4, 0); m_view->move(4, 0); std::cout << "RIGHT" << std::endl; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)){ p_sprite.move(0, 4); m_view->move(0, 4); std::cout << "DOWN" << std::endl; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)){ p_sprite.move(0, -4); m_view->move(0, -4); std::cout << "UP" << std::endl; }
}
void Lester::Screen()
{
window->setView(*m_view);//Set Game View
Map();//Call Map
window->draw(m_map);
PlayerSetup();
}
void Lester::GameScreen()
{
window->setView(*m_view);
window->clear();
Screen();
}
void Lester::GameLoop()
{
window = new sf::RenderWindow(sf::VideoMode(960, 550, 32), "Lester V:0.1");
m_view = new sf::View(sf::FloatRect(200, 200, 300, 200));//View Port
m_view->zoom(0.7f);//Set Zoom
window->setFramerateLimit(60);//Set FrameRate
window->setVerticalSyncEnabled(true);
p_sprite.setPosition(300, 250);
while (window->isOpen())
{
sf::Event event;
while (window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
window->close();
}
running = true;
while (splash_set == false){window->display();splash_set = true;}
if (splash_set == true){ window->clear(); KeyInput();PlayerSetup(); GameScreen(); window->display(); }
}
}
void Lester::Init(){ GameLoop(); }