SFML community forums
Help => Graphics => Topic started by: Fantasy on July 03, 2011, 10:49:15 pm
-
hello everyone
so i'm trying to make a load map function and draw map function but i cant get it to work correctly, here is the code.
#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>
#include <fstream>
int Map[100][100];
int loadCounterX=0;
int loadCounterY=0;
int mapSizeX;
int mapSizeY;
bool once=false;
void LoadMap (const char *filename)
{
std::ifstream openfile(filename);
if(openfile.is_open())
{
while(!openfile.eof())
{
if(once==false)
{
openfile>>mapSizeX>>mapSizeY;
once = true;
}
openfile >> Map[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX>=mapSizeX)
{
loadCounterX=0;
loadCounterY++;
}
}
}
}
void DrawMap()
{
for(int i=0; i<mapSizeX; i++)
for(int a=0; a<mapSizeY; a++)
Game.Draw(Map[i][a]);
}
int WindowWidth = 800, WindowHight = 600, ColorDepth = 32;
std::string WindowTitle = "The Final Game !!!";
sf::RenderWindow Game(sf::VideoMode(WindowWidth, WindowHight, ColorDepth), WindowTitle);
int main()
{
sf::Event Event;
const char *tiles[2];
tiles[1]=("Data/Images/grass.png");
tiles[2]=("Data/Images/dirt.png");
Game.SetFramerateLimit(60);
while(Game.IsOpened())
{
while(Game.GetEvent(Event))
{
}
Game.Clear();
Game.Display();
}
return 0;
}
text file
10 2
1111111111
0000000000
-
You never call DrawMap
-
You never call DrawMap
well here is the problem i cant do Game.Draw(Map[a]) it gives me error
-
Were you expecting to draw an int? :roll:
-
You can only pass a derivative of Drawable to the Draw function.
-
I think you're forgetting a whole lot here, a hint:
Learn how to use classes, then create classes for:
Map
Tile
The mapclass should have an std::vector<Tile> Tiles; from wich you can iterate when drawing and saving maps, checking collisions and so fort.
The tileclass should have reference to wich image it should draw, wich position it should be in etcetcetc.
These are just guidelines to create a "working" result, and i can promise you it can be done so much better if you really give your heart into learning the stuff you are working with, so you understand every bit of it. Or close at least.
-
I had a similar problem, then after a few minutes of searching I found this (http://www.dreamincode.net/forums/topic/230524-c-tile-engine-from-scratch-part-1/). Hope it helps.
But be aware, that code there is a bit flawed. Read the comments. Especially Part 4, otherwise you'll end up with some nasty memory leaks.
-
I had a similar problem, then after a few minutes of searching I found this (http://www.dreamincode.net/forums/topic/230524-c-tile-engine-from-scratch-part-1/). Hope it helps.
But be aware, that code there is a bit flawed. Read the comments. Especially Part 4, otherwise you'll end up with some nasty memory leaks.
thank you so much you have no idea how much this article helped me, thank you.
thankx guys