Hello
. So i made gameobject class where is stored sprite and texture. So i when i try to move sprite from my gameobject* it's not moving (x value is not changing).
Graphics.cpp:
void openWindow() {
window.create(sf::VideoMode(800, 800), Game::getGameName());
window.setVerticalSyncEnabled(true);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
Game::closeGame();
break;
}
}
window.clear();
GameObject::GameObject* gameobject = GameObject::getGameObject("player_gameobject");
sf::Sprite sprite = gameobject->getSprite();
sf::Texture texture = gameobject->getTexture();
sprite.setTexture(texture);
sprite.move(5, 0);
window.draw(sprite);
window.display();
}
}
GameObject.cpp:
#include "GameObject.h"
#include <unordered_map>
namespace GameObject {
std::unordered_map<std::string, GameObject> gameobjects;
GameObject::GameObject() {
name = "";
sprite = sf::Sprite();
texture = sf::Texture();
}
GameObject::GameObject(std::string gameobject_name, sf::Sprite gameobject_sprite, sf::Texture gameobject_texture, int gameobject_position_x, int gameobject_position_y) {
name = gameobject_name;
sprite = gameobject_sprite;
texture = gameobject_texture;
sprite.setPosition(gameobject_position_x, gameobject_position_y);
}
void addGameObject(GameObject gameobject) {
gameobjects[gameobject.getName()] = gameobject;
}
void removeGameObject(std::string gameobject_name) {
gameobjects.erase(gameobject_name);
}
GameObject* getGameObject(std::string gameobject_name) {
return &gameobjects[gameobject_name];
}
}
And my GameObject class:
class GameObject {
private:
std::string name;
sf::Sprite sprite;
sf::Texture texture;
public:
GameObject();
GameObject(std::string gameobject_name, sf::Sprite gameobject_sprite, sf::Texture gameobject_texture, int gameobject_position_x, int gameobject_position_y);
void setName(std::string gameobject_name) {
name = gameobject_name;
}
void setSprite(sf::Sprite gameobject_sprite) {
sprite = gameobject_sprite;
}
void setTexture(sf::Texture gameobject_texture) {
texture = gameobject_texture;
}
std::string getName() {
return name;
}
sf::Sprite getSprite() {
return sprite;
}
sf::Texture getTexture() {
return texture;
}
};
I hope someone can help me
. Thanks.
*UPDATE* i also tried gameobject->getSprite().move(3, 0); and nothing happens...