How to access dynamic variable - c++

class dynamic
{
public:
dynamic();
void value();
void move();
sf::RectangleShape rs;
};
dynamic::dynamic()
{
rs.setSize(sf::Vector2f(200,200));
rs.setFillColor(sf::Color::Red);
rs.setPosition(300, 300)
};
void dynamic::move()
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
spr.move(0, 1);
value();
}
}
void dynamic::value()
{
return spr.getposition.y
}
---------------- Diffrent Class ---------------
class context : public dynamic {
public:
void valueWrite();
};
void context::valueWrite(){
std::cout << spr.getposition.y;
}
---------------- Game Class ---------------
class Game {
public:
Game();
void draw();
void update();
void loop();
sf::RenderWindow window;
context m_context;
dynamic m_dynamic;
};
game::game(): window(sf::VideoMode(800, 600), "SFML window")
{
}
void game::loop()
{
while (window.isOpen())
{
update();
draw();
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
}
}
}
}
void game::draw()
{
window.clear();
m_dynamic.render(window);
window.display();
}
void game::update()
{
m_dynamic.move();
m_context.valueWrite();
}
When I run this program of main, my spr position evertime same.
Console = 300 300 300 300 300.........
I want to write the current value of the class context
How to fix this problem.

In this code m_dynamic and m_context objects independent from each other. The value that m_context try to write is not m_dynamic's value.
You should create just a "context" object. And you will call "move" function from "context" object.
m_context.move();
m_context.valueWrite();
and render too.

Related

Why is my SFML sprite not showing texture?

I'm trying to create a game. I have a class GameObjects that many classes will inherit from. The class GameObject has a draw method that takes the window address to the display. Why does the sprite show up without the texture when displayed like this?
This is the texture, more of a placeholder. I was able to load it in other files directly creating the sprite and drawing it.
Here is my main.cpp
#include <iostream>
#include "Game.h"
int main()
{
//window setup
Game game;
//Initialize game
game.start();
return 0;
}
Here is my Game.h
#pragma once
#include "GameObject.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
class Game
{
private:
//window variables
int w_width;
int w_height;
sf::RenderWindow window;
sf::Event ev;
bool isRunning;
std::vector<GameObject> o_vector;
void initVariables();
void initWindow();
void initObjects();
void drawObjects();
public:
void start();
void run();
void input();
void update();
void render();
};
And Game.cpp
#include "Game.h"
#include "GameObject.h"
void Game::start()
{
this->initVariables();
this->initWindow();
this->initObjects();
this->run();
}
//Initializations
void Game::initVariables()
{
isRunning = true;
//window variables
w_width = 1280;
w_height = 720;
}
void Game::drawObjects()
{
for (int o_count = 0; o_count < o_vector.size(); o_count++)
{
o_vector.at(o_count).draw(window);
}
}
void Game::initWindow()
{
//window creation
window.create(sf::VideoMode(w_width, w_height), "The Dungeon Crawler", sf::Style::Titlebar | sf::Style::Close | sf::Style::Resize);
}
void Game::initObjects()
{
GameObject baseObject;
o_vector.push_back(baseObject);
}
void Game::run()
{
while (isRunning)
{
input();
update();
render();
}
}
void Game::input()
{
while (window.pollEvent(ev))
{
switch (ev.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
switch (ev.key.code)
{
case sf::Keyboard::Escape:
window.close();
break;
case sf::Keyboard::A:
break;
}
}
}
}
void Game::update()
{
}
void Game::render()
{
window.clear(sf::Color(0, 0, 128));
drawObjects();
window.display();
}
Here is GameObject.h
#pragma once
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
class GameObject
{
private:
std::string name;
std::vector<int> o_position;
std::vector<int> o_size;
std::string t_path;
sf::Sprite o_sprite;
sf::Texture o_texture;
void initVariables();
public:
//Constructors & Destructors
GameObject();
~GameObject();
//Getters
std::vector<int> getPos();
std::vector<int> getSize();
sf::Sprite getSprite();
//Setters
void setPos(std::vector<int>pos_in);
void setSize(std::vector<int> size_in);
//Graphics
void draw(sf::RenderWindow &displayWindow);
};
And GameObject.cpp
#include "GameObject.h"
GameObject::GameObject()
{
initVariables();
}
GameObject::~GameObject()
{
}
void GameObject::initVariables()
{
o_position = { 0,0 };
o_size = { 64,64 };
t_path = "Resources/EmptySquare.png";
if (!o_texture.loadFromFile(t_path))
{
std::cout << "Failed to load" << std::endl;
return;
}
o_sprite.setTexture(o_texture);
}
std::vector<int> GameObject::getPos()
{
return o_position;
}
std::vector<int> GameObject::getSize()
{
return o_size;
}
sf::Sprite GameObject::getSprite()
{
return o_sprite;
}
void GameObject::setPos(std::vector<int> pos_in)
{
o_position = pos_in;
}
void GameObject::setSize(std::vector<int> size_in)
{
o_size = size_in;
}
void GameObject::draw(sf::RenderWindow &displayWindow)
{
displayWindow.draw(o_sprite);
}
Thank you for any help!
the problem is this line in Game::initObjects()
GameObject baseObject;
o_vector.push_back(baseObject);
you creata a copy of GameObject.
so it will make a copy of o_sprite.
the o_sprite copies the texture pointer.
after this function ends, the texture pointer is no longer valid.
sf::Sprite has the member const Texture* m_texture; and when calling sf::Sprite::setTexture(const Texture& texture) this member m_texture will in fact point to the texture. That texture will be destructed after initObjects() ends, and your element at position 0 will have a o_sprite.m_texture that points to this destructed object. SFML/Sprite.hpp
you could define the correct operator=(GameObject) that implements the correct sprite copy - or in this case simply say:
void Game::initObjects()
{
o_vector.resize(1);
}
resize will call the constructor of GameObject and you will have no copies and therefore dangling pointers.
Another way would be for you to allocate game object on the heap and store a pointer to it in the vector. This way you will avoid the cost of copying.
To make these changes, declare baseObject as private member of Game class and in initObjects method allocate it on the heap.
class Game
{
private:
GameObject *baseObject;
std::vector<GameObject *> o_vector;
};
void Game::initObjects()
{
baseObject = new GameObject;
o_vector.push_back(baseObject);
}
void Game::drawObjects()
{
for (int o_count = 0; o_count < o_vector.size(); o_count++)
{
o_vector.at(o_count)->draw(window); // use -> operator to call draw
}
}
PS: Instead of raw pointer, you can also use C++11 smart pointer.

How to run rendering thread properly from class with function inside that class?

I have this error at my project with threads and I dont know how to solve it. I tryed std::thread and sf::Thread. Could someone help please?
Im creating Animation object inside main class and through function runThread() I am trying to launch thread inside the Animation class.
Error log:
Failed to activate the window's context
Failed to activate OpenGL context
My solution
Main class
int main()
{
bool launchThreads = true;
sf::RenderWindow window(sf::VideoMode( 800, 600), "Title" );
Animation* anima = new Animation(window);
sf::Event event;
while(window.isOpen())
{
while (window.pollEvent(event))
{
anima->handleEvent(event);
if (event.type == sf::Event::Closed)
{
delete anima;
anima = nullptr;
window.close();
}
}
window.clear(sf::Color::Black);
here I am trying to launch that thread:
if (launchThreads)
{
anima->runThread();
launchThreads = false;
}
window.display();
}
return 0;
}
Animation.h :
class Animation
{
private:
sf::RenderWindow& window;
sf::RectangleShape* rectPtr;
sf::Vector2f mousePos;
sf::Thread thread;
public:
Animation(sf::RenderWindow& window);
void handleEvent(sf::Event event);
void runThread();
void handleDraw();
~Animation();
};
and Animation.cpp :
Animation::Animation(sf::RenderWindow& window) : thread(&Animation::handleDraw, this), window(window),rectPtr(nullptr), mousePos()
{
//sf::Thread thea(&handleDraw);
//thread = thea;
rectPtr = new sf::RectangleShape;
rectPtr->setSize(sf::Vector2f(100, 100));
rectPtr->setFillColor(sf::Color::Red);
}
void Animation::handleEvent(sf::Event event)
{
switch (event.type)
{
case sf::Event::MouseMoved:
mousePos = window.mapPixelToCoords(sf::Vector2i(event.mouseMove.x, event.mouseMove.y));
break;
}
}
void Animation::runThread()
{
thread.launch();
}
void Animation::handleDraw()
{
for (size_t i = 0; i < 10; i++)
{
rectPtr->setPosition(i*110, 10);
if (rectPtr->getGlobalBounds().contains(mousePos))
{
rectPtr->setFillColor(sf::Color::Yellow);
}
else rectPtr->setFillColor(sf::Color::Red);
window.draw(*rectPtr);
}
}
Animation::~Animation()
{
thread.terminate();
delete rectPtr;
rectPtr = nullptr;
}
Solution:
Solved with moving function window.display(); inside handleDraw() and moving context there too by window.setActive(); App shows what it have to. But inside console there are still same errors.. Think I can Ignore them.

Can't draw sf::RectangleShape s stored in vector (Tetris clone)

I am trying to storesf::RectangleShape's into thestd::vectorand then draw each of them into thesf::RenderWindow.
Single rectangle shape is representing 1x1 tetromino and i would like to store it into the vector each time it reaches the bottom of the window. Then I would like to reset the position of the current tetromino to the default position.
I think I'm not even to able store it correctly. Each time the tetromino reaches the bottom it gives me this error message:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Bellow please find my current code. I just started working on it and already got stuck.
Definitions.h
#pragma once
// Point structure
struct Point
{
int dim_x;
int dim_y;
};
// Field Dimensions
const int fieldRows = 10;
const int fieldColumns = 9;
const int pointSize = 50.f;
// For checkingEdges funntion within the Tetrnomino.h
enum Edge
{
leftEdge,
rightEdge,
noneEdge
};
Game.h
#pragma once
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "Definitions.h"
#include "Tetromino.h"
class Game
{
public:
Game();
~Game();
// Game starter
void run();
// Accessors
bool running();
private:
// Updating and rendering the game window
void update();
void render();
// Initialization
void initVariables();
void initWindow();
void initBacgroundMusic();
// Polling
void pollEvents();
// Window logic stuff
sf::RenderWindow* _window;
sf::Event _event;
void drawStack();
// Bacground Music
sf::Music _ost;
// Tetromino + Its logic
Tetromino _T;
sf::Time delayTime = sf::milliseconds(300);
sf::Clock clock;
};
Tetromino.h
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>
#include "Definitions.h"
class Tetromino
{
public:
Tetromino();
~Tetromino();
// Initialization
void initTetromino();
// Tetromonino logic
void moveTetromino();
Edge checkEdges();
// Getters & Setters
sf::RectangleShape getTetromino();
sf::RectangleShape getStackPart(int part);
int getStackSize();
void setTetromino(sf::RectangleShape &t);
private:
// The current tetromino
sf::RectangleShape _tetromino;
std::vector<sf::RectangleShape> _stack;
};
Game.cpp
#include "Game.h"
//-----Consturcotrs and Destructors-----//
Game::Game()
{
//Basic Initialization
_T.initTetromino();
initVariables();
}
Game::~Game()
{
delete _window;
}
//-----Private Functions-----//
void Game::run()
{
update();
render();
}
bool Game::running()
{
return _window->isOpen();
}
void Game::update()
{
sf::Time elapsed = clock.getElapsedTime();
pollEvents();
if (elapsed >= delayTime)
{
_T.moveTetromino();
clock.restart();
}
}
void Game::render()
{
_window->clear(sf::Color::White);
_window->draw(_T.getTetromino());
drawStack();
_window->display();
}
void Game::initVariables()
{
_window = nullptr;
initWindow();
initBacgroundMusic();
}
void Game::initWindow()
{
_window = new sf::RenderWindow(sf::VideoMode(fieldColumns * pointSize, fieldRows * pointSize), "Tetris v0.2", sf::Style::Default);
_window->setVerticalSyncEnabled(true);
_window->setFramerateLimit(60);
}
void Game::initBacgroundMusic()
{
_ost.openFromFile("../QT_SFML_Tetris/Music.ogg");
_ost.play();
_ost.setLoop(true);
_ost.setVolume(50.f);
}
void Game::pollEvents()
{
while (_window->pollEvent(_event))
{
if (_event.type == sf::Event::Closed) {_window->close();}
if (_event.type == sf::Event::KeyPressed)
{
if (_event.key.code == sf::Keyboard::Escape){_window->close();}
if (_event.key.code == sf::Keyboard::Left && _T.checkEdges() != leftEdge)
{
sf::RectangleShape t = _T.getTetromino();
t.setPosition(t.getPosition().x - pointSize, t.getPosition().y);
_T.setTetromino(t);
render();
}
if (_event.key.code == sf::Keyboard::Right && _T.checkEdges() != rightEdge)
{
sf::RectangleShape t = _T.getTetromino();
t.setPosition(t.getPosition().x + pointSize, t.getPosition().y);
_T.setTetromino(t);
render();
}
if (_event.key.code == sf::Keyboard::Down)
{
sf::RectangleShape t = _T.getTetromino();
t.setPosition(t.getPosition().x, t.getPosition().y+ pointSize);
_T.setTetromino(t);
render();
}
}
}
}
**void Game::drawStack()**
{
for (unsigned int i = _T.getStackSize(); i > 0; --i)
{
_window->draw(_T.getStackPart(i));
}
}
main.cpp
#include <Game.h>
int main()
{
Game game;
while (game.running())
{
game.run();
}
return 0;
}
Tetromino.cpp
#include "Tetromino.h"
//-----Consturcotrs and Destructors-----//
Tetromino::Tetromino()
{
}
Tetromino::~Tetromino()
{
}
//-----Public Functions-----//
void Tetromino::initTetromino()
{
_tetromino.setPosition(sf::Vector2f((fieldColumns * pointSize - pointSize) / 2, 0.f));
_tetromino.setSize(sf::Vector2f(pointSize, pointSize));
_tetromino.setFillColor(sf::Color::Red);
}
void Tetromino::moveTetromino()
{
_tetromino.move(0.f, pointSize);
if (_tetromino.getPosition().y > fieldRows * pointSize - pointSize)
{
_stack.push_back(_tetromino);
_tetromino.setPosition(sf::Vector2f((fieldColumns * pointSize - pointSize) / 2, 0.f));
}
}
Edge Tetromino::checkEdges()
{
if (_tetromino.getPosition().x == 0)
{
return leftEdge;
}
else if (_tetromino.getPosition().x == (fieldColumns * pointSize) - pointSize)
{
return rightEdge;
}
else return noneEdge;
}
sf::RectangleShape Tetromino::getTetromino()
{
return _tetromino;
}
sf::RectangleShape Tetromino::getStackPart(int part)
{
return _stack[part];
}
int Tetromino::getStackSize()
{
return _stack.size();
}
void Tetromino::setTetromino(sf::RectangleShape &t)
{
_tetromino = t;
}
I think the main issue could be within this line:
_stack.push_back(_tetromino);
In the drawStack() method you try to iterate backwards.
There is a reverse iterator doing this for you.
you have an off-by one error in your index calculation, which works only with an empty vector (exactly to prevent these errors you should use the iterator!)
You may want to read about iterators in C++ here is a small example.
According to your code it will look like (note that you need also a getStack()-method in Tetromino.hpp, returning the reference of the vector):
void Game::drawStack()
{
for (auto it = _T.getStack().rbegin(); it != _T.getStack().rend(); it++)
{
_window->draw(*it);
}
}
If you want to keep the index, I this is a fix:
void Game::drawStack()
{
for (int i = _T.getStackSize()-1; i >= 0; --i)
{
_window->draw(_T.getStackPart(i));
}
}

I have a Segfault, bad allocation?

This is my code :
t_game_elements *initializeEnvironnement(sf::RenderWindow *window)
{
t_game_elements *gameElements;
playerBat playerBatOne(0, 200);
playerBat playerBatTwo(790, 200);
gameElements = (t_game_elements *)malloc(1000);
gameElements->playerOne = playerBatOne;
gameElements->playerTwo = playerBatTwo;
*gameElements->playerOne.getShape();
window->draw(*playerBatOne.getShape()); // this line don't segfault
window->draw(*gameElements->playerOne.getShape()); // this line segfault
return (gameElements);
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 500), "Pong", sf::Style::Default);
t_game_elements *elements;
elements = initializeEnvironnement(&window);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Escape)
{
window.close();
}
}
if (event.type == sf::Event::Closed)
window.close();
}
// window.clear();
// window.draw(*elements->playerOne.getShape());
// window.draw(*elements.playerTwo->getShape());
window.display();
}
return 0;
}
class playerBat
{
public:
playerBat(int x, int y);
sf::RectangleShape *getShape();
void setShape(sf::RectangleShape *Shape);
int test = 10;
private:
sf::RectangleShape shapeBat;
};
typedef struct s_game_elements
{
playerBat playerOne;
playerBat playerTwo;
} t_game_elements;
playerBat::playerBat(int x, int y)
{
sf::RectangleShape rectangle(sf::Vector2f(120, 50));
rectangle.setSize(sf::Vector2f(10, 100));
rectangle.setPosition(x, y);
rectangle.setFillColor(sf::Color::Green);
shapeBat = rectangle;
}
void playerBat::setShape(sf::RectangleShape *Shape)
{
shapeBat = *Shape;
}
sf::RectangleShape *playerBat::getShape()
{
return &shapeBat;
}
I allocate 1000 bytes just to be sure I allocate enough memory, I will change it when I will fix the segfautlt first.
I tried to display the variable 'test' of my class and it works fine.
Have an idea why I segfault ?
Thanks

While loop confusion

Question:
My while loop is not exiting. During debugging it has says very specifically that stateID is equal to 3. However, when I add std::cout << stateID; the value 1 is always written to the console, no matter what the debugger is telling me.
In the code, I render the screen after the input loop. This shows that, without a doubt, the input loop exits properly, as expected. Also, if that is not enough, It would have to exit for the stateID to change in the first place. Please, no more discussion of the nested loop being the issue. And I have also used breakpoints after the loop which are properly hit.
Code:
int main()
{
stateID = 1;
GameState* state = new GameStateTitle();
sf::RenderWindow window(sf::VideoMode(1000, 600), "RPG");
//GAME LOOP//
while (stateID != 3)
{//INPUT//
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
//Window closed
case sf::Event::Closed:
set_next_state(3);
break;
}
}
change_state(state);
//RENDERING//
window.clear(sf::Color::Black);
state->render(window);
window.display();
}
/////////////
window.close();
return 0;
}
void set_next_state(int new_state)
{
//Set the next state to take place
next_state = new_state;
}
void change_state(GameState *current_state)
{
//Check if the next state is null or exit
if (next_state != 0)
{
if (next_state != 3)
delete current_state;
//Set the new state
switch(next_state)
...
}
stateID = next_state;
next_state = 0;
}
}
Below is my full code, in case I missed something important.
Main.cpp
#include "GameState.hpp"
int main()
{
stateID = STATE_TITLE;
GameState* state = new GameStateTitle();
sf::RenderWindow window(sf::VideoMode(1000, 600), "RPG");
//GAME LOOP//
while (stateID != STATE_EXIT)
{
//INPUT//
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
//Window closed
case sf::Event::Closed:
set_next_state(STATE_EXIT);
break;
}
}
///////////
////LOGIC//
state->logic();
///////////
change_state(state);
//RENDERING//
window.clear(sf::Color::Black);
state->render(window);
std::cout << stateID;
window.display();
/////////////
}
///////////////
window.close();
return 0;
}
GameState.hpp
#pragma once
#include <SFML/Graphics.hpp>
//DEFINITIONS ETC//
enum GAME_STATES {
STATE_NULL,
STATE_TITLE,
STATE_BATTLE,
STATE_EXIT
};
///////////////////
//Game State Class//
class GameState
{
public:
virtual void input(void) = 0;
virtual void logic(void) = 0;
virtual void render(sf::RenderWindow &window) = 0;
};
////////////////////
//FUNCTIONS//
void set_next_state(int new_state);
void change_state(GameState *current_state);
/////////////
//VARIABLES//
static int stateID;
static int next_state;
/////////////
//Title GameState Class//
class GameStateTitle : public GameState
{
private:
sf::Texture img_title;
sf::Sprite bgr_title;
public:
GameStateTitle(void);
~GameStateTitle(void);
void input(void);
void logic(void);
void render(sf::RenderWindow &window);
};
/////////////////////////
//Battle GameState Class//
class GameStateBattle : public GameState
{
private:
sf::Image img_left;
sf::Image img_right;
public:
GameStateBattle(void);
~GameStateBattle(void);
void input(void);
void logic(void);
void render(sf::RenderWindow &window);
};
//////////////////////////
GameState.cpp
#include "GameState.hpp"
//Game state general functions
void set_next_state(int new_state)
{
//Set the next state to take place
next_state = new_state;
}
void change_state(GameState *current_state)
{
//Check if the next state is null or exit
if (next_state != STATE_NULL)
{
if (next_state != STATE_EXIT)
delete current_state;
//Set the new state
switch(next_state)
{
case STATE_TITLE:
current_state = new GameStateTitle;
break;
case STATE_BATTLE:
current_state = new GameStateBattle;
break;
}
stateID = next_state;
next_state = STATE_NULL;
}
}
//The functions of the title state
GameStateTitle::GameStateTitle(void)
{
//Load texture
img_title.loadFromFile("title_screen.png");
//Set texture to background
bgr_title.setTexture(img_title);
}
GameStateTitle::~GameStateTitle(void)
{
}
void GameStateTitle::input(void)
{
}
void GameStateTitle::logic(void)
{
}
void GameStateTitle::render(sf::RenderWindow &window)
{
window.draw(bgr_title);
}
//The functions of the battle state
GameStateBattle::GameStateBattle(void)
{
}
GameStateBattle::~GameStateBattle(void)
{
}
void GameStateBattle::input(void)
{
}
void GameStateBattle::logic(void)
{
}
void GameStateBattle::render(sf::RenderWindow &window)
{
}
You have two while loops. The condition in the outer while will never be tested until the inner loop exits.
Consider using just one loop, with a single condition.
sf::Event event;
while ( (stateID != 3) && window.pollEvent(event)) {
}
You are breaking out of the switch and not out of the while.
The program below (attempts to) duplicate your code.
It works as expected, with both loops ending when they are supposed to.
Btw, this is what we call a short, contained, correct example.
Correct as in compilable, using globals such as stateID or magic numbers such as the 3 in while (stateID != 3) is bad form and not the mark of a professional.
How does your program deviate from the one below?
#define STATE_TITLE 2
#define STATE_BATTLE 3
#define STATE_NULL 0
int stateID;
int next_state;
struct Event
{
Event(int Num) : type(Num){}
Event() : type( 5 ){} // random number grater than 1
enum Type
{
Closed = 1 // equivalent to sf::Event::Closed
};
int type;
};
class Window
{
public:
int pollEvent( Event& Ev )
{
return --Ev.type;
}
};
void set_next_state(int new_state)
{
next_state = new_state;
}
void change_state()
{
if (next_state != STATE_NULL)
{
stateID = next_state;
next_state = STATE_NULL;
}
}
int _tmain()
{
stateID = STATE_TITLE;
Window window;
//GAME LOOP//
while (stateID != 3)
{//INPUT//
Event event;
// note that there is at least one event with a Closed type before window.pollEvent(event) return false (0)
while (window.pollEvent(event))
{
switch (event.type)
{
//Window closed
case Event::Closed:
set_next_state(3);
break;
}
}
change_state();
}
return 0;
}
I changed the function change_state to the following:
void change_state(GameState *current_state, int &ID)
{
//Check if the next state is null or exit
if (next_state != STATE_NULL)
{
if (next_state != STATE_EXIT)
delete current_state;
//Set the new state
switch(next_state)
{
case STATE_TITLE:
current_state = new GameStateTitle;
break;
case STATE_BATTLE:
current_state = new GameStateBattle;
break;
}
ID = next_state;
next_state = STATE_NULL;
}
}
The issue must've been within the declaration of stateID, because it was never being changed in this function.