Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - osidu2

Pages: [1]
1
Graphics / Re: Window draws a white screen instead of map
« on: August 06, 2017, 01:22:31 am »
Oh Ok, I see. I will check this out for sure and post whether I managed to overcome the problem or not. Im really gratefull for your answer.

2
Graphics / Window draws a white screen instead of map
« on: August 06, 2017, 12:53:46 am »
Hello guys,
So I wanted to draw a tile map, making each tile a different object and then store them in vector, so I can go through it, and tile by tile draw them on the screen. The problem is that instead of a tile map, I get a clean white screen. I'm posting a code, could you help me?

That's my tile map class.

Quote
#pragma once

#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include "tile.h"
#include <vector>

class TileMap
{
public:
   std::string source;
   std::vector <Tile> tileContainer;
   TileMap(std::string mapSource)
   {
      source = mapSource;
   }


   void readMap()
   {
      std::fstream plik;
      std::string stringId;
      sf::Vector2f loadCounter(0, 0);
      plik.open(source, std::ios::in || std::ios::out);
      if (plik.good())
      {
         while (!plik.eof())
         {
            plik >> stringId;
            int id = stoi(stringId);
            if (id == 0)
            {
               Tile tile(id, "tiles.png", sf::Vector2f(32, 32));
               tileContainer.push_back(tile);
            }
            else if (id == 1)
            {
               Tile tile(id, "tiles.png", sf::Vector2f(128, 32));
               tileContainer.push_back(tile);
            }
         }
      }
   }


   void drawMap(sf::RenderWindow &okno)
   {

      sf::Vector2f loadCounter(0, 0);
      if (tileContainer.size() != 0)
      {
         for (int i = 0; i < tileContainer.size(); i++)
         {
            tileContainer.sprite.setPosition(loadCounter.x * 32, loadCounter.y * 32);
            okno.draw(tileContainer.sprite);
            std::cout << tileContainer.id;
            loadCounter.x++;
            if (loadCounter.x == 16)
            {
               loadCounter.x = 0;
               loadCounter.y++;
               if (loadCounter.y == 16)
               {
                  loadCounter.y = 0;
                  loadCounter.x = 0;
               }
            }
         }
      }
   }
};

and that's my tile class
Quote
#pragma once

#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

class Tile
{
public:
   float id;
   sf::Texture texture;
   sf::FloatRect bounds;
   sf::Sprite sprite;
   bool walkable;
   Tile(float tileId, std::string tileSource,sf::Vector2f graphCords)
   {
      id = tileId;
      texture.loadFromFile(tileSource);
      sprite.setTexture(texture);
      float x = graphCords.x;
      float y = graphCords.y;
      sprite.setTextureRect(sf::IntRect(x,y, 32, 32));
   }
};

Pages: [1]
anything