That's actually the problem.Because its iterating through the array its not displaying all of it at once.It only shows the last array number chosen.Any ideas on how to iterate through this in a way that it displays all of the array at once?
#include <SFML\Graphics.hpp>
#include <iostream>
#include "declare.h"
#include <fstream>
using namespace sf;
using namespace std;
int beforetilenum;
int tilenum;
int usedtiles;
int main()
{
Texture floor000;
Sprite tileguide;
Sprite tile[50];
floor000.loadFromFile("image/floor000.png",IntRect(120,0,120,60));
tileguide.setTexture(floor000);
RenderWindow window(VideoMode(600, 480),"Blupi Empire");
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
window.close();
}
///go through tile[] array number////
if(beforetilenum<50)
{
beforetilenum+=1;
}
if(beforetilenum==50)
{
beforetilenum=0;
}
/////tilenum = unused sprites number/////////
if(tile[beforetilenum].getTexture()==NULL)
{
tilenum=beforetilenum;
}
else
{
usedtiles=beforetilenum;
}
//////GRID WEB//////////////
Vector2i Position=Mouse::getPosition(window);
if(tileguide.getPosition().y<Position.y&&tileguide.getPosition().x<Position.x)
{
//bottom right
tileguide.setPosition(tileguide.getPosition().x+60,tileguide.getPosition().y);
tileguide.setPosition(tileguide.getPosition().x,tileguide.getPosition().y+30);
}
if(tileguide.getPosition().y>Position.y&&tileguide.getPosition().x>Position.x)
{
//topleft
tileguide.setPosition(tileguide.getPosition().x-60,tileguide.getPosition().y);
tileguide.setPosition(tileguide.getPosition().x,tileguide.getPosition().y-30);
}
if(tileguide.getPosition().y<Position.y&&tileguide.getPosition().x>Position.x)
{
//bottomleft
tileguide.setPosition(tileguide.getPosition().x-60,tileguide.getPosition().y);
tileguide.setPosition(tileguide.getPosition().x,tileguide.getPosition().y+30);
}
if(tileguide.getPosition().y>Position.y&&tileguide.getPosition().x<Position.x)
{
//top right
tileguide.setPosition(tileguide.getPosition().x+60,tileguide.getPosition().y);
tileguide.setPosition(tileguide.getPosition().x,tileguide.getPosition().y-30);
}
////////PLACE SELECTION////////////////
if(Mouse::isButtonPressed(Mouse::Left))
{
tile[tilenum].setTexture(floor000);
tile[tilenum].setPosition(tileguide.getPosition().x,tileguide.getPosition().y);
window.draw(tile[tilenum]);
ofstream myfile;
myfile.open ("map.txt");
myfile << "tile["<<tilenum<<"].setTexture(floor000);"<<endl;
myfile << "tile["<<tilenum<<"].setPosition("<<tileguide.getPosition().x<<","<<tileguide.getPosition().y<<");"<<endl;
myfile.close();
}
window.display();//The only way that I see to display every part of the array is to display it twice,which flickers of course.
window.clear();
window.draw(tileguide);
window.display();
}
}