Hi guys
I am writing here, because i need Your help.
The problem is how to excatly draw a sprite of a class?
main.cpp
#include <SFML/Window.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include "Mob.h"
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 1000), "Title");
window.setPosition(sf::Vector2i(320, 0));
window.setVerticalSyncEnabled(true); // call it once, after creating the window
Mob mob1;
mob1.attack(10);
mob1.setskin("zombie");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::White);
mob1.render(window);
window.display();
}
return 0;
}
Mob.h
#ifndef MOB_H_INCLUDED
#define MOB_H_INCLUDED
#include <SFML/Window.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <sstream>
#include <windows.h>
#include <ctime>
#include <cstdlib>
using namespace std;
class Mob
{
private:
int hp;
int mana;
int ad;
sf::Texture T_skin;
sf::Sprite skin;
public:
void attack(int amount);
void sethp();
void setskin(std::string name);
void render(sf::RenderWindow& i);
};
#endif // MOB_H_INCLUDED
mob.cpp
#include <iostream>
#include "Mob.h";
void Mob::attack(int amount)
{
std::cout << "You attacked someone\n";
}
void Mob::setskin(string name)
{
if(T_skin.loadFromFile(name+".png"))
{
skin.setTexture(T_skin);
skin.setTextureRect(sf::IntRect(0, 0, T_skin.getSize().x, T_skin.getSize().y));
skin.setPosition(sf::Vector2f(640, 290));
cout << "I'm setting the \"Skin\" option\n";
}
}
void Mob::render(sf::RenderWindow& i)
{
i.draw(skin);
}
The problem is exactly in Mob::render() and main loop in main() - no error(img loaded, run as admin)
I would really appreciate Your help(explanations, examples).