sfml - vector[0].getPosition() returns 0 - c++

I was making a simple snake game but when I tried moving a part of my snake
it went to 0,0.
I keep all parts of my snake inside a vector.
But when I do something like
vector[0].getPosition()
//(In my code: snakeParts[0].getPosition())
It just returns 0,0.
I also don't get any error whilst compiling.
Here's my code:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <unistd.h>
#include <vector>
using namespace std;
sf::RenderWindow App(sf::VideoMode(854, 480), "Snake");
sf::RectangleShape snake;
sf::RectangleShape snake2;
vector<sf::RectangleShape> snakeParts;
string movingDirection = "Right";
int updatePos() {
snakeParts[1].setPosition(snakeParts[0].getPosition()); //Where my problem lies
if (movingDirection == "Left") {
snake.move(-32,0);
}
else if (movingDirection == "Right") {
snake.move(32,0);
}
else if (movingDirection == "Up") {
snake.move(0,-32);
}
else if (movingDirection == "Down") {
snake.move(0,32);
}
//for (int i=0; i<snakeParts.size(); i++) {
//int target = snakeParts.size()-i;
}
int main()
{
snake.setSize(sf::Vector2f(32, 32));
snake.setFillColor(sf::Color::Green);
snake2.setSize(sf::Vector2f(32, 32));
snake2.setFillColor(sf::Color::Red);
snakeParts.push_back(snake);
snakeParts.push_back(snake2);
while (App.isOpen())
{
sf::Event event;
while (App.pollEvent(event))
{
if (event.type == sf::Event::Closed)
App.close();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
movingDirection = "Left";
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
movingDirection = "Right";
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
movingDirection = "Down";
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
movingDirection = "Up";
}
}
usleep(100000);
//cout << movingDirection << endl;
updatePos();
App.clear();
App.draw(snake);
App.draw(snake2);
App.display();
}
return 0;
}
I think it's something to do with pointers?
But I wouldn't know how I would fix that...

Dump those global snakeN variables! Are you going to declare everything up to snake100 if you want to have 100 cells? Your vector is storing copies (those are left untouched on (0, 0)), on which you should be performing all the logic.
Make all other global variables local to a function or member of a class and use function parameters where needed.
movingDirection should be an enum.
updatePos with its current signature should return something.

Related

Game does not launch from Menu

I am new to Game Development. I managed to create a simple game (like Space Invaders) as well as a simple start Menu using C++ and SFML. However, upon pressing "Enter" on the main menu, the game is not being launched. How do I link it properly? I appreciate your help. This is not homework.
main.cpp codes
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "GameObjectManager.h"
#include "Menu.h"
using namespace std;
int main()
{
sf::Texture galaxyBackgroundTexture;
sf::Sprite galaxyBackground;
if (!galaxyBackgroundTexture.loadFromFile("Textures/galaxybackground.png")) {
cout << "Failed to load Image" << endl;
}
galaxyBackground.setTexture(galaxyBackgroundTexture);
sf::RenderWindow window(sf::VideoMode(1200, 800), "Space Invader Test");
Menu menu(window.getSize().x, window.getSize().y);
window.setFramerateLimit(144);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Key::Return)
{
menu.GetPressedItem();
cout << "Play button has been pressed." << endl;
GameObjectManager* gameObjectManagerManager = new GameObjectManager(&window);
gameObjectManager->update();
gameObjectManager->render(window);
}
else if (event.type == sf::Event::Closed)
{
window.close();
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
{
window.close();
}
}
window.clear();
window.draw(galaxyBackground);
menu.draw(window);
window.display();
}
return 0;
}
Menu.h
#pragma once
#include "SFML/Graphics.hpp"
#define MAX_NUMBER_OF_ITEMS 2
class Menu
{
public:
Menu(float width, float height);
~Menu();
void draw(sf::RenderWindow& window);
int GetPressedItem() { return selectedItemIndex; }
private:
int selectedItemIndex;
sf::Font font;
sf::Text menu[MAX_NUMBER_OF_ITEMS];
};
Menu.cpp
#include "Menu.h"
Menu::Menu(float width, float height)
{
if (!font.loadFromFile("arial.ttf"))
{
cout << "can't load font" << endl;
}
// initialise Menu items
menu[0].setFont(font);
menu[0].setColor(sf::Color::Red);
menu[0].setString("Play");
menu[0].setPosition(sf::Vector2f(width / 2, height / (MAX_NUMBER_OF_ITEMS + 1) * 1));
// EXIT
menu[1].setFont(font);
menu[1].setColor(sf::Color::White);
menu[1].setString("Exit");
menu[1].setPosition(sf::Vector2f(width / 2, height / (MAX_NUMBER_OF_ITEMS + 1) * 2));
}
selectedItemIndex = 0;
Menu::~Menu()
{
}
void Menu::draw(sf::RenderWindow &window)
{
for (int i = 0; i < MAX_NUMBER_OF_ITEMS; i++)
{
window.draw(menu[i]);
}
}
The console window would print:
"Play button has been pressed"
But it does not proceed to the game. Nothing else happens.
"window redefinition" error occurs because both your RenderWindow objects have the same identifiers (i.e. window). You might want to change the name of the second window or better yet use the same window.
The second error, sf::Text::setColor() is deprecated means that it is no longer "useable" or "is not suggested to be used". SFML has two new better functions for this:
sf::Text::setFillColor() : to set the fill of your text.
sf::Text::setOutlineColor() : to give your text an outline (you also need to do change the thickness using setOutlineThickness()).
Moreover, I'd suggest you to use a State Machine for different scenes instead of two separate windows. It really isn't that difficult and will help you learn a few more things. You're somewhat already achieving this with your gameObjectManager. You just need to abstract it and implement it for your menu class as well. And since you have only two scenes you can simply use an integer or boolean to switch between these two.
EDIT: an idea of what you need to do to your main.cpp file
int main()
{
sf::RenderWindow window(sf::VideoMode(1200, 800), "Space Invader Test");
GameObjectManager* gameObjectManagerManager = nullptr;
bool inGame = false; //true = game has started, false = menu screen
while (window.isOpen())//this is the main loop
{
sf::Event event;
while (window.pollEvent(event)) //this is the event loop
{
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Key::Return)
{
if(!inGame)
{
if(menu.GetPressedItem() == PlayButton) //assuming your function returns which button in the menu has been pressed
{
cout << "Play button has been pressed." << endl;
inGame = true;
gameObjectManagerManager = new GameObjectManager(&window);
}
else
{
window.close(); //since the other button is exit
}
}
}
if (event.type == sf::Event::Closed) window.close();
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) window.close();
}
//this is the place where you call your updates
if(inGame) gameObjectManagerManager->update();
window.clear();
window.draw(galaxyBackground);
if(!inGame)menu.draw(window);
if(inGame) gameObjectManagerManager->render();
window.display();
}
return 0;
}

Vector2i doesn't want to cooperate:D

My problem is that in the:
if(Keyboard::isKeyPressed(Keyboard::D))
{
source.y=right;
source.x++;
}
fragment of my simple code, the source.y doesn't want to take the value of 0. What's causing this?
Full code:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <conio.h>
#include <windows.h>
#define CW 64//cell width
using namespace std;
using namespace sf;
int main()
{
RenderWindow win(VideoMode(1200,800),"lol");
win.setFramerateLimit(30);
Texture t;
t.loadFromFile("char.png");
Sprite char_;
char_.setTexture(t);
enum dir{right,left,idle};
Vector2i source(1,idle);
while(win.isOpen())
{
win.clear();
if(Keyboard::isKeyPressed(Keyboard::D))
{
source.y=right;
source.x++;
}
if(Keyboard::isKeyPressed(Keyboard::A))
{
source.y=left;
source.x++;
}
else
{
source.y=idle;
}
char_.setTextureRect(IntRect(source.x*CW,source.y*CW,CW,CW));
if(source.x==3 || source.x>3)
{
source.x=0;
}
cout<<"source.x: "<<source.x<<endl;
cout<<"source.y: "<<source.y<<endl;
win.draw(char_);
win.display();
system("cls");
}
}
You are missing an else after your first if:
if(Keyboard::isKeyPressed(Keyboard::D))
{
source.y=right;
source.x++;
}
if(Keyboard::isKeyPressed(Keyboard::A))
{
source.y=left;
source.x++;
}
else
{
source.y=idle;
}
Even if D is pressed, you will end up in the final else clause, because it's not A. So source.y will take the value of right, but will immediately be overwritten by the line source.y=idle;
What you probably want (check the else in front of the second if) is:
if(Keyboard::isKeyPressed(Keyboard::D))
{
source.y=right;
source.x++;
}
else if(Keyboard::isKeyPressed(Keyboard::A))
{
source.y=left;
source.x++;
}
else
{
source.y=idle;
}

Sfml pollEvent, every new image deletes the previous one

My problem is that the function don't do what I want.
This "CreateWindow" function has the main loop. In the main loop I want a fixed background and, every time I press the H button, I want to draw a Card (sprite) on the background.
What's the problem here? My function draw the cards but when I press H the previous card is deleted and the next card is drawn.
This is something about the event I think, because every time an event happens (I move the mouse, I press an other key etc) the previous card is deleted...
I'm using sfml 2.0
Here is my implementation of the Graphic class
#include "Graphic.h"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <string>
#include "Card.h"
#include <string>
#include <sstream>
Graphic::Graphic(int offset)
{
this->offset = offset;
}
Graphic::~Graphic()
{
//dtor
}
int Graphic::CreateWindow(sf::RenderWindow& window, Deck &deck0)
{
sf::Vector2i screenDimensions(800, 600);
//Dimensioni della window
window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "BlackJack", sf::Style::Titlebar | sf::Style::Close);
int index = 0;
window.setKeyRepeatEnabled(false);
//settare il background
sf::Texture bTexture;
sf::Sprite bImage;
if(!bTexture.loadFromFile("Background.png"))
std::cout << "Error" << std::endl;
bImage.setTexture(bTexture);
bImage.setScale(1.0, (float)screenDimensions.y / bTexture.getSize().y);
//MAIN LOOP----------------------
while(window.isOpen())
{
sf::Event Event;
while(window.pollEvent(Event))
{
window.clear();
window.draw(bImage); // this is the function which draw the background
if (Event.type == sf::Event::Closed)
{
window.close();
}
if(Event.key.code == sf::Keyboard::H)
{
Card * y = deck0.dealFirst();
drawCard(window,y->graphNumber,y->getSeed(),offset);
offset = offset + 50;
}
window.display();
}
}
}
int Graphic::drawCard(sf::RenderWindow &window, int graphNumber, string seed, int offset)
{
std::ostringstream oss;
oss << graphNumber << seed << ".png";
std::string var = oss.str();
sf::Texture QHTexture;
sf::Sprite QHImage;
if(!QHTexture.loadFromFile(var))
std::cout<< "Error" <<std::endl;
QHImage.setTexture(QHTexture);
QHImage.setScale(0.5, 0.5);
QHImage.setPosition(offset + 100, 400);
window.draw(QHImage); //this is the function which draw the card's sprite
return 0;
}
Alright you shouldn't be drawing inside of your while(window.pollEvent()) loop, you should be drawing something like this:
while(window.isOpen())
{
sf::Event Event;
while(window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
{
window.close();
}
if(Event.key.code == sf::Keyboard::H)
{
Card * y = deck0.dealFirst();
drawCard(window,y->graphNumber,y->getSeed(),offset);
offset = offset + 50;
}
}
window.clear();
window.draw(bImage); // this is the function which draw the background
window.display();
}
The way you were drawing your draw call will only happen if there is an SFML event, and will only ever clear if there is an sfml event(Which is ok if you dont want it to constantly render every frame... and aren't planning any kind of animations...).
So when you hit H an sfml event was being triggers that called your draw card function, however since your card is a local variable to the function you wrote, at the end of the function it is cleared out. You need to store your cards somewhere, such as a vector or list of sf::Sprite. So an example would be:
#include "Graphic.h"
#include "SFML/Graphics.hpp"
#include <iostream>
#include <string>
#include "Card.h"
#include <string>
#include <sstream>
Graphic::Graphic(int offset)
{
this->offset = offset;
}
Graphic::~Graphic()
{
//dtor
}
int Graphic::CreateWindow(sf::RenderWindow& window, Deck &deck0)
{
sf::Vector2i screenDimensions(800, 600);
//Dimensioni della window
window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "BlackJack", sf::Style::Titlebar | sf::Style::Close);
int index = 0;
window.setKeyRepeatEnabled(false);
//settare il background
sf::Texture bTexture;
sf::Sprite bImage;
if(!bTexture.loadFromFile("Background.png"))
std::cout << "Error" << std::endl;
bImage.setTexture(bTexture);
bImage.setScale(1.0, (float)screenDimensions.y / bTexture.getSize().y);
//MAIN LOOP----------------------
while(window.isOpen())
{
sf::Event Event;
while(window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
{
window.close();
}
if(Event.key.code == sf::Keyboard::H)
{
Card * y = deck0.dealFirst();
drawCard(window,y->graphNumber,y->getSeed(),offset);
offset = offset + 50;
}
}
window.clear();
window.draw(bImage); // this is the function which draw the background
for(int i = 0; i < cardList.size(); ++i)
{
window.draw(cardList[i]);
}
window.display();
}
}
int Graphic::drawCard(sf::RenderWindow &window, int graphNumber, string seed, int offset)
{
std::ostringstream oss;
oss << graphNumber << seed << ".png";
std::string var = oss.str();
sf::Texture QHTexture;
sf::Sprite QHImage;
if(!QHTexture.loadFromFile(var))
std::cout<< "Error" <<std::endl;
QHImage.setTexture(QHTexture);
QHImage.setScale(0.5, 0.5);
QHImage.setPosition(offset + 100, 400);
cardList.push_back(QHImage); //this adds the sprite to our list
return 0;
}

C++/SFML Graphing Application-Repeating Texture/Sprite

I was taking up the challenge of creating a program to use for graphing simple math equations using C++ and the SFML 2.3.2. graphics library, and I've got the graph paper texture rendering fine. However, the problem I've had is getting it to repeat itself as I scroll around.
I was using sf::View to get it to pan, and it works well, but as soon as it pans outside the pre-defined size of the sprite it's just a blank background.
I thought of trying to determine when I'm outside the bounds of the sprite, and then expanding the size of the sprite or moving it, but then drawings (such as a graph) won't persist if the sprite is changed/reset.
What I need to know is how to create a background of a texture, in this case graphing paper, that will tile/repeat in every direction, and allow drawings to be made on top of it that persist if they move off screen.
Code is below:
GraphPaper.h:
#pragma once
#include "stdafx.h"
class GraphPaper
{
public:
GraphPaper();
~GraphPaper();
bool isObjectLoaded();
sf::Sprite getSprite();
private:
void load(std::string filename);
bool isLoaded;
sf::Texture texture;
sf::Sprite sprite;
const std::string file = "images/Graph-Paper.png";
};
GraphPaper.cpp: This is where I create and load the needed sprite and texture.
I set the texture to repeat inside the "load(string filename)" method, but that only affects it within the bounds set by the sprite's rectangle.
#include "GraphPaper.h"
GraphPaper::GraphPaper() : isLoaded(false)
{
load(file);
assert(isObjectLoaded());
}
GraphPaper::~GraphPaper() {};
void GraphPaper::load(std::string filename)
{
if (texture.loadFromFile(filename) == false)
isLoaded = false;
else
{
texture.setRepeated(true);
sprite.setTexture(texture);
//Huge size to at least make it look like it's infinite,
//but a temporary solution.
sprite.setTextureRect(sf::IntRect(0,0,10000,10000));
isLoaded = true;
}
}
bool GraphPaper::isObjectLoaded()
{
return isLoaded;
}
sf::Sprite GraphPaper::getSprite()
{
return sprite;
}
MainWindow.h:
#pragma once
#include "GraphPaper.h"
#include "stdafx.h"
class MainWindow
{
public:
void close();
void start();
void moveCamera(sf::Event);
private:
bool leftMousePressed, rightMousePressed, isExiting;
int r, g, b, mouseX, mouseY;
GraphPaper paper;
const sf::Color white = sf::Color(255, 255, 255);
sf::RenderWindow mainWindow;
sf::View view;
};
MainWindow.cpp: This is what handles all the drawing, and, at the moment, all input processing. "start()" is simply called from the main method.
#include "MainWindow.h"
#include "GraphPaper.h"
#include "stdafx.h"
void MainWindow::start()
{
sf::RectangleShape rectangle = sf::RectangleShape(sf::Vector2f(120, 50));
rectangle.setFillColor(sf::Color(0,0,0));
mainWindow.create(sf::VideoMode(1024, 768, 32), "Test");
sf::View view(sf::FloatRect(0,0,1000,600));
mainWindow.setView(view);
leftMousePressed, rightMousePressed, isExiting = false;
sf::Event currentEvent;
mainWindow.clear(white);
mainWindow.draw(paper.getSprite());
mainWindow.display();
while (!isExiting)
{
while (mainWindow.pollEvent(currentEvent))
{
switch (currentEvent.type)
{
case sf::Event::MouseMoved:
{
if (rightMousePressed == true)
{
std::cout << "Mouse Panned\n";
}
if (leftMousePressed == true)
{
std::cout << "Mouse is Drawing\n";
}
break;
}
case sf::Event::MouseButtonPressed:
{
std::cout << "Mouse Pressed\n";
mouseX = currentEvent.mouseButton.x;
mouseY = currentEvent.mouseButton.y;
if (currentEvent.mouseButton.button == sf::Mouse::Left)
{
leftMousePressed = true;
}
else if (currentEvent.mouseButton.button == sf::Mouse::Right)
{
rightMousePressed = true;
}
break;
}
case sf::Event::MouseButtonReleased:
{
std::cout << "Mouse Released\n";
if (currentEvent.mouseButton.button == sf::Mouse::Left)
{
leftMousePressed = false;
}
else if(currentEvent.mouseButton.button == sf::Mouse::Right)
{
rightMousePressed = false;
}
break;
}
case sf::Event::KeyPressed:
{
if (currentEvent.key.code == sf::Keyboard::Escape)
{
close();
}
//No right movement yet, was testing.
else if (currentEvent.key.code == sf::Keyboard::Left)
{
moveCamera(currentEvent);
}
break;
}
case sf::Event::Closed:
{
close();
break;
}
}
}
}
}
void MainWindow::moveCamera(sf::Event key)
{
std::cout << "Inside moveCamera\n";
//No right movement yet, was testing.
//Movement is also hardcoded for testing as well.
view.move(100, 0);
mainWindow.setView(view);
mainWindow.clear(white);
mainWindow.draw(paper.getSprite());
mainWindow.display();
std::cout << "Leaving moveCamera\n";
}
void draw()
{
//mainWindow.draw();
}
void MainWindow::close()
{
std::cout << "Closing...\n";
mainWindow.close();
isExiting = true;
}

Namespaces acting weird

Ok guys... I'm coding my first game using SFML and I have found the awesomely hateful problem... I'll explain.
main.cpp
#include "include/SFML/include/SFML.hpp"
#include "include/menu.h"
#include <iostream>
#include <fstream>
#include "include/checkfileexistence.h"
#include "include/fonts.h"
#define FPS 20
bool loadFonts();
bool loadMenu();
int main ()
{
if (!loadFonts()) {std::cout << "Could not load fonts!"; return EXIT_FAILURE;}
sf::RenderWindow window (sf::VideoMode(0,0),"Evility", sf::Style::Fullscreen);
window.setFramerateLimit(FPS);
sf::Event event;
window.setKeyRepeatEnabled(false);
while (window.isOpen())
{
window.clear();
if (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed: {window.close(); break;}
case sf::Event::KeyPressed:
{
switch (event.key.code)
{
case sf::Keyboard::Escape: {window.close(); break;}
case sf::Keyboard::LAlt && sf::Keyboard::F4: {window.close(); break;}
}
}
}
}
if (menu::isBeingUsed)
{
if (!menu::isRunning)
{
if (!loadMenu()) {std::cout << "Could not load menu files!"; return EXIT_FAILURE;}
menu::music.setLoop(true);
menu::music.play();
menu::isRunning = true;
window.setVisible(true);
}
if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) || (sf::Keyboard::isKeyPressed(sf::Keyboard::W)))
{
menu::selectedOption--;
if (menu::selectedOption < 0)
{
menu::selectedOption = 3;
}
}
if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) || (sf::Keyboard::isKeyPressed(sf::Keyboard::S)))
{
menu::selectedOption++;
if (menu::selectedOption > 3)
{
menu::selectedOption = 0;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
{
switch (menu::selectedOption)
{
case 3:
{
window.close();
break;
}
}
}
switch (menu::selectedOption)
{
case 0:
menu::optionSelector.setPosition(sf::Vector2f(60,105));
break;
case 1:
menu::optionSelector.setPosition(sf::Vector2f(60,155));
break;
case 2:
menu::optionSelector.setPosition(sf::Vector2f(60,205));
break;
case 3:
menu::optionSelector.setPosition(sf::Vector2f(60,255));
break;
}
window.draw(menu::spriteBackground);
window.draw(menu::textStartGame);
window.draw(menu::textContinueGame);
window.draw(menu::textOptions);
window.draw(menu::textQuitGame);
window.draw(menu::optionSelector);
}
window.display();
}
}
bool loadFonts()
{
if (!font::ArcadePix.loadFromFile("resources/Fonts/ArcadePix.TTF"))
{
return false;
}
return true;
}
bool loadMenu ()
{
menu::music.openFromFile("resources/Music/Unity.wav");
menu::music.setLoop (true);
menu::textureBackground.loadFromFile("resources/wallpaper.png");
menu::spriteBackground.setTexture(menu::textureBackground, false);
menu::spriteBackground.setPosition(0,0);
menu::spriteBackground.setScale(window.getSize().width / menu::spriteBackground.getLocalBounds().width, window.getSize().height / menu::spriteBackground.getLocalBounds().height);
menu::optionSelector.setSize (sf::Vector2f(25,25));
menu::optionSelector.setFillColor(sf::Color::Yellow);
menu::optionSelector.setPosition(60,105);
menu::textStartGame.setFont(font::ArcadePix);
menu::textStartGame.setColor(sf::Color::Red);
menu::textStartGame.setPosition(sf::Vector2f(100,100));
menu::textStartGame.setString("Start Game");
menu::textContinueGame.setFont (font::ArcadePix);
if (fileExists("resources/Saves/saves.txt"))
{
menu::textContinueGame.setColor(sf::Color::Red);
}
else
{
menu::textContinueGame.setColor(sf::Color(211,211,211,127));
}
menu::textContinueGame.setPosition(100,150);
menu::textContinueGame.setString("Continue Game");
menu::textOptions.setFont(font::ArcadePix);
menu::textOptions.setColor(sf::Color::Red);
menu::textOptions.setPosition(100,200);
menu::textOptions.setString("Options");
menu::textQuitGame.setFont(font::ArcadePix);
menu::textQuitGame.setColor(sf::Color::Red);
menu::textQuitGame.setPosition(100,250);
menu::textQuitGame.setString("Quit Game");
return true;
}
menu.h
#ifndef MENU_H_
#define MENU_H_
#include "SFML/include/SFML.hpp"
namespace menu{
bool isBeingUsed = true;
bool isRunning = false;
sf::RectangleShape rectBackground (sf::Vector2f (1080,720));
sf::Texture textureBackground;
sf::Sprite spriteBackground;
sf::Text textStartGame;
sf::Text textContinueGame;
sf::Text textQuitGame;
sf::Text textOptions;
sf::RectangleShape optionSelector (sf::Vector2f(0,0));
unsigned int selectedOption;
sf::Music music;
}
#endif
So in the awesomely long function call in main.cpp, which I expect to happen, is for the program to look for a class inside the RenderWindow object window, for a class...
But instead, the function call refers to a class function inside a namespace, it also thinks window is in that namespace, because the compilation returns window was not declared in this scope which I presume means window was not declared in menu namespace.
How should I tell my program to look outside the menu namespace?
Peace.
Edit 1: Added all main.cpp code, didn't want to as it is the future code for a game but it is so simple I don't feel like nobody would steal it.
window is a variable that's local to main. Pass it to loadMenu if you need it there.