Non, j'ai seulement un écran noir qui s'affiche avec le sprite de mon perso mais sans la map.
voila ma page main (désolé, comme je débute mon code est très brouillon)
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <cctype>
#include "TileMap.h"
#include <array>
#include <vector>
#include "Character.h"
#include "Player.h"
#include "Animation.h"
#include "Main.h"
#include <cmath>
#include "Tile.h"
//void gestion_clavier();
int tileNbr(sf::Sprite playerSprite);
std::vector <Tile> tabTile ;
sf::Texture playerTexture;
sf::Sprite playerSprite;
enum Direction { Down, Left, Right, Up };
sf::Vector2i anim(1, Down);
int speed=2;
bool updateFPS = false;
sf::Clock animClock;
float fpsCount = 0, switchFps = 100, fpsSpeed = 500;
int currenTileX = 0, nbrRow=0,nbrCol=0;
bool screenTitleOn = true;
int selection = 1;
TileMap map;
int a;
sf::View view;
int main()
{
sf::Vector2i screenDimensions(1400, 763);
sf::RenderWindow window(sf::VideoMode(screenDimensions.x, screenDimensions.y), "My first SFML game");
window.setKeyRepeatEnabled(false);
a = screenDimensions.x;
window.setFramerateLimit(60);
float frameCounter = 0, switchFrame = 100, frameSpeed = 500;
//image de fond:
sf::Texture pTexture;
sf::Sprite fond;
//rectangle noir a placer sur l'image
sf::RectangleShape rect(sf::Vector2f((screenDimensions.x/100)*20, screenDimensions.y));
rect.setPosition((screenDimensions.x / 100) * 10, 0);
rect.setFillColor(sf::Color(0, 0, 0, 170));
//menu
sf::Font font;
sf::String newGame = "New Game";
sf::String continu = "Load Game";
sf::String options = "Options";
sf::String exit = "Exit";
sf::Text ng(newGame, font, 20);
sf::Text ctn(continu, font, 20);
sf::Text opt(options, font, 20);
sf::Text ext(exit, font, 20);
//rectangle de selection
sf::RectangleShape rectSelect(sf::Vector2f((screenDimensions.x / 100) * 20, 30));
rectSelect.setPosition((screenDimensions.x / 100) * 10, ((screenDimensions.y / 100) * 40));
rectSelect.setFillColor(sf::Color(255, 255, 255, 0));
rectSelect.setOutlineColor(sf::Color(255, 255, 255, 255));
rectSelect.setOutlineThickness(2.0f);
ng.setColor(sf::Color(255, 255, 255));
ctn.setColor(sf::Color(255, 255, 255));
opt.setColor(sf::Color(255, 255, 255));
ext.setColor(sf::Color(255, 255, 255));
if (!font.loadFromFile("arial.ttf"))
std::cout << "Error could not load the font file" << std::endl;
if (!pTexture.loadFromFile("SplashScreen.jpg"))
std::cout << "Error could not load player image" << std::endl;
fond.setTexture(pTexture);
ng.setPosition(((screenDimensions.x / 100) * 15), ((screenDimensions.y / 100) * 40));
ctn.setPosition(((screenDimensions.x / 100) * 15), ((screenDimensions.y / 100) * 45));
opt.setPosition(((screenDimensions.x / 100) * 15), ((screenDimensions.y / 100) * 50));
ext.setPosition(((screenDimensions.x / 100) * 15), ((screenDimensions.y / 100) * 55));
std::ifstream monFlux("demoSol.txt");
std::vector <int> tableau;
std::vector <int> tabOn;
std::vector <int> tabOff;
std::vector <int> tabBelow;
int nombre;
tabOn.push_back(56);
tabOff.push_back(19);
tabOff.push_back(28);
tabOff.push_back(33);
tabOff.push_back(36);
tabOff.push_back(48);
tabOff.push_back(49);
tabOff.push_back(50);
while (monFlux >> nombre)
tableau.push_back(nombre);
for (int a = 0; a < tableau.size(); a++)
{
tabTile.push_back(Tile(tableau[a], tabOn, tabOff, tabBelow));
}
//création du perso principale
!playerTexture.loadFromFile("knight.png");
playerSprite.setTexture(playerTexture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
}
if (event.type == sf::Event::KeyPressed)
updateFPS = true;
else
updateFPS = false;
currenTileX = std::abs(playerSprite.getPosition().x / 32);
if ((event.type == sf::Event::KeyPressed)&&(screenTitleOn==true))
{
if (event.key.code == sf::Keyboard::Up)
{
if (selection == 1)
{
selection = 4;
rectSelect.setPosition(((screenDimensions.x / 100) * 10), ((screenDimensions.y / 100) * 55));
}
else
{
selection--;
rectSelect.move(0, -((screenDimensions.y / 100) * 5));
}
}
else if (event.key.code == sf::Keyboard::Down)
{
if (selection == 4)
{
selection = 1;
rectSelect.setPosition(((screenDimensions.x / 100) * 10), ((screenDimensions.y / 100) * 40));
}
else
{
selection++;
rectSelect.move(0, ((screenDimensions.y / 100) * 5));
}
}
if (event.key.code == sf::Keyboard::Return)
{
switch (selection)
{
case 1:
screenTitleOn = false;
if (!map.load("tileset.png", sf::Vector2u(32, 32), tabTile, 50, 50))
return -1;
break;
case 4:
window.close();
break;
}
}
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
anim.y = Up;
playerSprite.move(0, -speed);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
anim.y = Down;
playerSprite.move(0, speed);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
nbrCol = std::abs(playerSprite.getPosition().x / 32);
nbrRow = std::abs(playerSprite.getPosition().y / 32);
currenTileX = (nbrRow * 50) + nbrCol+1;
/*if (tabTile[currenTileX])
{*/
anim.y = Right;
playerSprite.move(speed, 0);
//}
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
anim.y = Left;
playerSprite.move(-speed, 0);
}
if (playerSprite.getPosition().x <= 0)
playerSprite.setPosition(sf::Vector2f(0, playerSprite.getPosition().y));
if (playerSprite.getPosition().y <= 0)
playerSprite.setPosition(sf::Vector2f(playerSprite.getPosition().x,0));
if (updateFPS == true)
{
if (animClock.getElapsedTime().asMilliseconds() >= 50)
{
anim.x--;
if (anim.x * 32 >= playerTexture.getSize().x)
anim.x = 2;
animClock.restart();
}
}
playerSprite.setTextureRect(sf::IntRect(anim.x * 32, anim.y * 32, 32, 32));
//parametrage de la vue
view.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
sf::Vector2f position(screenDimensions.x/2, screenDimensions.y/2);
position.x = playerSprite.getPosition().x + 16 - (screenDimensions.x / 2);
position.y = playerSprite.getPosition().y + 16 - (screenDimensions.y / 2);
if (position.x < 0)
position.x = 0;
if (position.y < 0)
position.y = 0;
view.reset(sf::FloatRect(position.x, position.y, screenDimensions.x, screenDimensions.y));
window.clear();
window.draw(fond);
window.draw(rect);
window.draw(ng);
window.draw(ctn);
window.draw(opt);
window.draw(ext);
window.draw(rectSelect);
if (screenTitleOn == false)
{
window.clear();
window.setView(view);
window.draw(map);
window.draw(playerSprite);
}
window.display();
}
return 0;
}
int tileNbr(sf::Sprite playerSprite)
{
nbrCol = std::abs(playerSprite.getPosition().x / 32);
nbrRow = std::abs(playerSprite.getPosition().y / 32);
return currenTileX = (nbrRow * 50) + nbrCol;
}