SethGandy, on 24 January 2013 - 02:32 AM, said:
Spinning off of what St0n3y provided, I made some fixes to get this code to work for me in SFML2.0
I'm using Visual Studios 2012 Express too, if that makes any difference.
The only thing that was busted after some fine tuning was the texturemanager.AddTexture(texture) call.
I had to use a pointer like texturemanager->AddTexture(texture) instead.
Hope this helps anyone who's a noob like me!
/>/>/>/>/>/>
TextureManager.h
TextureManager.cpp
Tile.h
Tile.cpp
Engine.h
Engine.cpp
Main.cpp
I'm using Visual Studios 2012 Express too, if that makes any difference.
The only thing that was busted after some fine tuning was the texturemanager.AddTexture(texture) call.
I had to use a pointer like texturemanager->AddTexture(texture) instead.
Hope this helps anyone who's a noob like me!
TextureManager.h
#ifndef TEXTURE_MANAGER_H
#define TEXTURE_MANAGER_H
#include <SFML/Graphics.hpp>
#include <vector>
using namespace std;
class TextureManager{
private:
vector<sf::Texture> textureList;
public:
TextureManager();
~TextureManager();
void AddTexture(sf::Texture& texture);
sf::Texture& GetTexture(int index);
};
#endif
TextureManager.cpp
#include "TextureManager.h"
TextureManager::TextureManager(){
}
TextureManager::~TextureManager(){
}
void TextureManager::AddTexture(sf::Texture& texture){
textureList.push_back(texture);
}
sf::Texture& TextureManager::GetTexture(int index){
return textureList[index];
}
Tile.h
#ifndef TILE_H
#define TILE_H
#include <SFML/Graphics.hpp>
class Tile{
private:
sf::Sprite baseSprite;
public:
Tile(sf::Texture& texture);
~Tile();
void Draw(int x, int y, sf::RenderWindow* rw);
};
#endif
Tile.cpp
#include "Tile.h"
#include "SFML/Graphics.hpp"
Tile::Tile(sf::Texture& texture){
baseSprite.setTexture(texture);
}
Tile::~Tile(){
}
void Tile::Draw(int x, int y, sf::RenderWindow* rw){
baseSprite.setPosition(x, y);
rw->draw(baseSprite);
}
Engine.h
#ifndef _ENGINE_H
#define _ENGINE_H
#include <SFML\Graphics.hpp>
#include "TextureManager.h"
#include "Tile.h"
class Engine
{
private:
//SFML Render Window
sf::RenderWindow* window;
TextureManager* texturemanager;
//Initializes the engine
bool Init();
//Main Game Loop
void MainLoop();
//Renders one frame
void RenderFrame();
//Processes user input
void ProcessInput();
//Updates all Engine internals
void Update();
//Temporary
void LoadTextures();
Tile* testTile;
public:
Engine();
~Engine();
void Go(); //Starts the engine
};
#endif
Engine.cpp
#include "Engine.h"
#include <SFML\Graphics.hpp>
Engine::Engine()
{
}
Engine::~Engine()
{
delete window;
//this is so that the 'window = new sf::RenderWindow' is removed from memory when the engine stops)
delete texturemanager;
//this is so that the texturemanager is also deleted once the engine is stopped
}
bool Engine::Init()
{
texturemanager = new TextureManager();
window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "RPG");
if(!window)
return false;
LoadTextures();
return true;
}
void Engine::LoadTextures()
{
sf::Texture texture;
texture.loadFromFile("sprite1.png");
texturemanager->AddTexture(texture);
testTile = new Tile(texturemanager->GetTexture(0));
}
void Engine::RenderFrame()
{
window->clear();
testTile->Draw(0,0, window);
window->display();
}
void Engine::ProcessInput()
{
sf::Event evt;
//Loop through all window events
while(window->pollEvent(evt))
{
if(evt.type == sf::Event::Closed)
window->close();
}
}
void Engine::Update()
{
}
void Engine::MainLoop()
{
//Loop until our window is closed
while(window->isOpen())
{
ProcessInput();
Update();
RenderFrame();
}
}
void Engine::Go()
{
if(!Init())
throw "Could not initialize Engine";
MainLoop();
}
Main.cpp
#include <Windows.h>
#include "Engine.h"
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
Engine* engine = new Engine();
try
{
engine->Go();
}
catch(char* e)
{
MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_IConerror);
}
}
Hi
I have changed the names over but still get the same result i am not sure on how i can fix this the way you showed how to do it got rid of about 50 errors and thank you it was a lot of help. These are the only 2 problems i am having and would like to no why that is i have checked over your code to my code and there is nothing different between the 2 just this 1 name
your textureManager and my tileManager that is the only difference.
if you could point me in the right direction it would be much appreciated.
//Under Engine::~Engine()
{
delete window; this works fine
// but when i try to do
delete TileManager;
i get Error 1 error C2440: 'delete' : cannot convert from 'TileManager' to 'void *'
}
//Under init
bool Engine::Init()
{
tileManager = new TileManager();
I end up getting. Error 2 error C2679: binary '=' : no operator found which takes a right-hand operand of type
'TileManager *' (or there is no acceptable conversion)





MultiQuote



|