//Data.h
class Data
{
public:
bool playing=false;
float W_HEIGHT=576,W_WIDTH=768;
sf::Texture dirt,grass,water,man;
sf::Sprite layout[9][13];
sf::Text error;
sf::Font default_font;
int tiles[9][13]={
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2}
}; //1=water,2=dirt,3=grass
};
//Verifications.h
class Verifications : public Data
{
public:
sf::Texture getObject(int tile);
private:
};
//Verifications.cpp
#include "verifications.h"
sf::Texture Verifications::getObject(int tile)
{
switch(tile)
{
case 1:
{
return water;
} break;
case 2:
{
return dirt;
} break;
case 3:
{
return grass;
} break;
default:
return dirt;
//Add "default", return an X or ? or Message.
}
}
//actions.h
class Actions : public Data
{
public:
Verifications Ver;
Actions(sf::RenderWindow* temp) : win(temp)
{
}
void initgame();
void gameerror();
void loadscreen();
private:
sf::RenderWindow* win;
};
//loadscreen() in Actions.h
void Actions::loadscreen()
{
//win->clear(sf::Color(205,133,63));
//Ver.getObject(tiles[y][x])
for(int x=0,y=0;;x++)
{
if(x==12) {x=0;y++;}
if(y>8) {break;}
layout[y][x].setPosition(x*64,y*64);
layout[y][x].setTexture(Ver.getObject(tiles[y][x]));
std::cout<<tiles[y][x];
std::cout<<Ver.test();
win->draw(layout[y][x]);
}
win->display();
}
For some reason it doesn't display the dirt sf::Texture that should be from getObject(). The id is passed into getObject() by tiles[y][ x ] and if it gets 2, it should return the dirt sf::Texture.
But when I change the argument from Ver.getObject(tiles[y][ x ]) to just dirt , it displays everything how it should be.
I even tried directly passing2into getObject(),but it still doesn't display. So it's a problem with the return