Search Results

Search found 1 results on 1 pages for 'user2892932'.

Page 1/1 | 1 

  • Sprite not moving when using a function from another class SFML c++

    - by user2892932
    I have a Game.cpp, and I am calling a update function in my Player class. In my player update Function I have it to check for keyboard input, and it seems to work, but whenever I try to call the .move() function, it seems to not work. I get no errors either. I am new to sfml, and decent with c++. Help is appreciated! #include "Player.h" Player::Player(void): vel(0), maxvel(100) { Load("Assets/sss.png",true); } void Player::Update(sf::Sprite& p) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { moveObject(-3,0, p); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { moveObject(-3,0, p); } } Player::~Player(void) { } This is the GameObject cpp #include "GameObject.h" #include <iostream> GameObject::GameObject(void) { isLoaded = false; } void GameObject::Load(std::string flname, bool isPlayer) { if(!tex.loadFromFile(flname)) { EXIT_FAILURE; } else { if(isPlayer) { if(!tex.loadFromFile(flname, sf::IntRect(0,0,33,33))) { EXIT_FAILURE; } else { std::cout << "Loading image" << "\n"; filename = flname; spr.setTexture(tex); isLoaded = true; } } else { std::cout << "Loading image" << "\n"; filename = flname; spr.setTexture(tex); isLoaded = true; } } } void GameObject::Draw(sf::RenderWindow & window) { if(isLoaded) { window.draw(spr); window.display(); std::cout << "Sprite drew" << "\n"; } } void GameObject::setPos(float x, float y) { if(isLoaded) { spr.setPosition(x,y); } } sf::Vector2f GameObject::GetObjPos() { return spr.getPosition(); } sf::Sprite& GameObject::getSprite() { return spr; } void GameObject::moveObject(float x, float y, sf::Sprite& sp) { sp.move(x, y); } GameObject::~GameObject(void) { }

    Read the article

1