Hey guys,
if my english is not so good sry and if i say something wrong its because im a newbie in c++ and sfml
so my question is how can i put the SpriteTexture in the draw function that is in a other class
main.cpp
#include <iostream>
#include <SFML\Graphics.hpp>
#include "Player.h"
#include "GameWindow.h"
int main()
{
GameWindow runWindow;
runWindow.RunGameWindow();
return 0;
}
Player.h
#ifndef PLAYER_HPP
#define PLAYER_HPP
#include <iostream>
#include <SFML\Graphics.hpp>
#include "GameWindow.h"
class Player
{
public:
void CreatTexture();
void PlayerMovement();
private:
sf::Texture PlayerTexture;
sf::Sprite PlayerSprite;
};
#endif
Player.cpp
#include "Player.h"
void Player::CreatTexture()
{
if (!PlayerTexture.loadFromFile("Picture//rgs.png"))
{/*----------*/ }
PlayerSprite.setTextureRect(sf::IntRect(40, 0, 20, 18));
}
void Player::PlayerMovement()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
PlayerSprite.move(0.1 , 0);
PlayerSprite.setTextureRect(sf::IntRect(140, 0, 40, 40));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
PlayerSprite.move(-0.1 , 0);
PlayerSprite.setTextureRect(sf::IntRect(100, 0, 20, 30));
}
}
GameWindow.h
#ifndef GAMEWINDOW_HPP
#define GAMEWINDOW_HPP
#include <SFML\Graphics.hpp>
#include "Player.h"
class GameWindow
{
public:
GameWindow();
~GameWindow();
void RunGameWindow();
void Draw();
void Render();
private:
sf::RenderWindow *mainWindow;
sf::Event *mainEvent;
};
#endif
GameWindow.cpp
#include "GameWindow.h"
GameWindow::GameWindow()
{
mainWindow = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Red Ghost", sf::Style::Titlebar);
mainEvent = new sf::Event;
}
GameWindow::~GameWindow()
{
mainWindow = NULL;
mainEvent = NULL;
delete mainWindow;
delete mainEvent;
}
void GameWindow::RunGameWindow()
{
while (mainWindow->isOpen())
{
while (mainWindow->pollEvent(*mainEvent))
{/*----------*/
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
mainWindow->close();
}
Render();
}
}
void GameWindow::Draw()
{
/*I want put the PlayerSprite in this function or draw the PlayerSprite
on the window*/
}
void GameWindow::Render()
{
mainWindow->clear(sf::Color::White);
Draw();
mainWindow->display();
}
you guys can give me a other example too if this is to much
thanks