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

Author Topic: White window error (RESOLVED  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

TheGoldenFyre

  • Newbie
  • *
  • Posts: 18
    • View Profile
White window error (RESOLVED
« on: December 31, 2015, 01:54:34 pm »
Edit: I fixed it already, no need to help anymore.


Okay... I'm trying to use a .txt (Already am using a .cpp file to prevent errors) file to load a map into a game. But wen I run my code, I get blank white screen (SFML window) with which I can do nothing. I get no errors, although I did get RAM reading errors before.
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <fstream>
#include <iostream>

sf::Sprite Sprite[2];
sf::Texture grass;
sf::Texture brick;
char textChar[2];
int numCharacters = 0;
int i = 0;

sf::RenderWindow window(sf::VideoMode(512, 384), "Map testing");


int main() {   
        std::ifstream myfile("Map test.cpp");
        //Specific to my images, I know bad names...
        brick.loadFromFile("New Piskel.png");
        grass.loadFromFile("Grass_double.jpg");
        while (window.isOpen())
        {
               
                window.clear();
                if (myfile.is_open())
                {
                        while (!myfile.eof())
                        {
                                myfile >> myArray[i];
                                i++;
                                num_characters++;
                        }

                        for (i = 0; i <= num_characters;)
                        {
                                if (myArray[i] == '1') {
                                        Sprite[i].setTexture(brick);
                                        window.draw(Sprite[i]);
                                        i++;
                                }
                                if (myArray[i] == '2') {
                                        Sprite[i].setTexture(grass);
                                        Sprite[i].setPosition(64, 0); //For testing purposes
                                        window.draw(Sprite[i]);
                                        i++;
                                }
                        }
                                sf::Event event;
                                while (window.pollEvent(event))
                                {
                                        if (event.type == sf::Event::Closed)
                                                window.close();
                                }
                                window.display();
                        }
                }
        }

(Please do not comment on the lack of comments, I am aware of that)

Can someone please help me with this? The .cpp contains the text "12" and the images are 64 by 64. I really have no idea what's going wrong.

Edit: I'm using an Amd processor and Windows 10 x64.

« Last Edit: December 31, 2015, 03:25:55 pm by TheGoldenFyre »

Satus

  • Guest
Re: White window error
« Reply #1 on: December 31, 2015, 03:17:10 pm »
Well, there are lots of things to improve in your code, but you should start with loading map from file only once and not every
  while (window.isOpen())
iteration.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: White window error (RESOLVED
« Reply #2 on: December 31, 2015, 03:29:35 pm »
To follow on from what Satus said, the event loop and clear, draw, display should be done every iteration, not just when the file is open.

Why is your map data in a .cpp file? How does that solve errors? I do wonder if this file is attempted to be compiled.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*