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 - The Illusionist Mirage

Pages: 1 ... 6 7 [8]
106
Graphics / Re: Loading tile maps
« on: August 12, 2013, 12:35:45 pm »
Quote
@ lockandstrike

Thanks, I'll then focus on the intermediate and hard ones.


107
Graphics / Re: Loading tile maps
« on: August 12, 2013, 12:05:23 pm »
@Ixrec

http://www.sfml-dev.org/tutorials/2.1/graphics-sprite.php#the-white-square-problem

In this specific case, it looks like you're trying to read the string "Map.png" from the file "Map.txt", but the Map.txt you've posted doesn't contain the string "Map.png". Did you leave part of it out?

Also, you should probably do error checking on the loadFromFile call:

if( !tileTexture.loadFromFile(tileLocation) )
    //output an error message of some kind or simply exit the program
 

Thanks! As you said I forgot(or rather was unaware) that the string "Map.png" is absent from "Map.txt"

Now everything is working as expected.

Thanks!

108
General / Re: Game window not working
« on: August 11, 2013, 06:32:43 pm »
Quote
@binary1248

No, it is a bit more involved than that. Look for a guide, it's too much to explain here.

I tried here: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks. But unfortunately still the same problem is persisting. I am in a fix cause thiugh the project is building, its not running.

109
Graphics / Loading tile maps
« on: August 11, 2013, 06:08:17 pm »
Hello

Here's my code which I've been following from the CodingmadeEasy tutorials series on SFML 2.0:


#include<SFML/Graphics.hpp>
#include<fstream>
#include<iostream>
#include<cctype>
using namespace std;
 
int main()
{
    std::ifstream openfile("Map.txt");
 
    sf::Vector2i map[100][100];
    sf::Vector2i loadCounter(0, 0);
    sf::Vector2i mapSize;
    sf::Texture tileTexture;
    sf::Sprite tiles;
 
    if(openfile.is_open())
    {
        std::string tileLocation;
        openfile >> tileLocation;
        std::cout << tileLocation << std::endl;
        tileTexture.loadFromFile(tileLocation);
        tiles.setTexture(tileTexture);
        while(!openfile.eof())
        {
            std::string tile;
            openfile >> tile;
            char x = tile[0], y = tile[2];
            //std::cout << "x: " << x << "y: " << y << std::endl;
            if(!isdigit(x) || !isdigit(y))
                map[loadCounter.x][loadCounter.y] = sf::Vector2i(-1, -1);
            else
                map[loadCounter.x][loadCounter.y] = sf::Vector2i(x - '0', y - '0');
 
            std::cout << map[loadCounter.x][loadCounter.y].x << "," << map[loadCounter.x][loadCounter.y].y << " ";
             
            if(openfile.peek() == '\n')
            {
                loadCounter.x = 0;
                loadCounter.y++;
                std::cout << std::endl;
            }
            else
                loadCounter.x++;
        }
        mapSize = loadCounter;
        mapSize.y++;
    }
 
    sf::RenderWindow Window(sf::VideoMode(640, 480, 32), "Loading Tile Maps[Easy]");
 
    while(Window.isOpen())
    {
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch (Event.type)
            {
            case sf::Event::Closed:
                Window.close();
                break;
            }
        }
 
        Window.clear();
 
        for(int i = 0; i < mapSize.x; i++)
        {
            for(int j = 0; j < mapSize.y; j++)
            {
                if(map[i][j].x != -1 && map[i][j].y != -1)
                {
                    tiles.setPosition(i * 32, j * 32);
                    tiles.setTextureRect(sf::IntRect(map[i][j].x * 32, map[i][j].y * 32, 32, 32));
                    Window.draw(tiles);
                }
            }
        }
 
        Window.display();
    }
 
    return 0;
}
 

His output is:



But my output is this:



I've made sure that Map.txt is the project directory and so is Map.png.

Here are they:

Map.txt
---------------------------------------------------------------------------------------------------------------------------------------
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
x,x x,x x,x x,x 0,1 1,0 1,1 x,x x,x x,x
x,x x,x x,x x,x x,x x,x x,x x,x x,x x,x
0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0 0,0
---------------------------------------------------------------------------------------------------------------------------------------

Map.png



It would be helpful if I am told the error I am commiting.

Thanks

110
General / Re: Game window not working
« on: August 11, 2013, 04:36:08 pm »
Quote
@binary1248
So.... what happens when you debug it? If you don't know how to debug your application in Code::Blocks, I'm sure you'll be able to find another tutorial for that...

Yes, I know how to debug. Set build target to debug and then build it, right?

Quote
@The Hatchet
Did you remember to move the DLL files over to your working directory as well?  These are needed if you link the dynamic version vs static.

Yes I've put the DLLs into the project folder.

111
General / Re: Game window not working
« on: August 11, 2013, 02:31:23 pm »
Quote
@lockandstrike

It's already been said, but in your code, where there is a "if(GameWindow.pollEvent(GameEvent))" statement there should be a "while(GameWindow.pollEvent(GameEvent))" statement. Change the code and post the result of that.

I changed it to while and its still not working. I've recompiled SFML 2.0 again from the beginning and tried to make it work with Code::Blocks.

Here's what I have been doing:

First, I downloaded the SFML source from here https://github.com/SFML/SFML/tarball/master

Then, extracted the files from the zip.

Next I compiled them using Cmake using the command line as per as the instructions on this site : http://sfmlcoder.wordpress.com/2011/06/16/building-sfml-2-0-with-mingw-make/

After compiling everything (Debug and Release), I opened up Code::Blocks 12.11 and went to the compiler settings and added the include and lib directories of SFML 2.0(I added those lib files which I compiled).

Then, I created a new console app, went to its project build options and in the linker setting tab added these:
for debug,
sfml-graphics-d
sfml-system-d
sfml-window-d

for release,
sfml-graphics
sfml-system
sfml-window


Then I added this code:


#include <SFML/Graphics.hpp>
#include <iostream>

const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
const int WINDOW_BPP = 32;
const char *WINDOW_CAPTION = "MY_SFML";

int main()
{
    sf::RenderWindow Window;
    Window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP),
                  WINDOW_CAPTION, sf::Style::Close);

    while(Window.isOpen())
    {
        sf::Event Event;

        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    {
                        Window.close();
                    } break;
                case sf::Event::KeyPressed:
                    {
                        if(Event.key.code == sf::Keyboard::Escape)
                        {
                            Window.close();
                        }
                    } break;
            }
        }

        Window.display();
    }
}


Uptill this, everything went on as expected. But when I added a few lines to display a circle:

#include <SFML/Graphics.hpp>
#include <iostream>

const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
const int WINDOW_BPP = 32;
const char *WINDOW_CAPTION = "MY_SFML";

const float CIRCLE_RADIUS = 100.0f;

int main()
{
    sf::RenderWindow Window;
    Window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP),
                  WINDOW_CAPTION, sf::Style::Close);

    sf::Time Time;
    sf::Clock Clock;

    sf::CircleShape Circle(CIRCLE_RADIUS);
    Circle.setFillColor(sf::Color::Green);

    while(Window.isOpen())
    {
        sf::Event Event;

        // Now I've also put pollEvent in a while loop as members
        // AlejandroCoria and lockandstrike pointed out
        while(Window.pollEvent(Event))  
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    {
                        Window.close();
                    } break;
                case sf::Event::KeyPressed:
                    {
                        if(Event.key.code == sf::Keyboard::Escape)
                        {
                            Window.close();
                        }
                    } break;
            }
        }

        Time = Clock.getElapsedTime();

        std::cout << Time.asSeconds() << std::endl;

        Window.draw(Circle);                   // problem started after //
        Window.display();
        Window.clear();                        // adding these two lines //
    }
}
 

The pgrogram is building, but when I run it, the console window and sfml window appear and then the sfml window turns white and a windows dialog saying mysfmlprogram.exe has stopped working and windows is looking for a solution. After that nothing happens until I close it.


EDIT:
quoted lockandstrike's reply

112
General / Re: Game window not working
« on: August 10, 2013, 12:16:58 pm »
Problem still persisting. I am doing fine with SFML 2.0 in Visual Studio 12 but still couldn't figure out what's wrong with my Code::Blocks setup and why am i able to display a SFML 2.0 window but not draw anything to it.

113
General / Re: Game window not working
« on: August 09, 2013, 03:23:37 pm »
Quote
Sounds like you have compiler/linker settings messed up somewhere. Are you sure your not mixing debug and release and that you have the correct libs for your compiler?

I followed this tutorial to set up SFML:


As far as I can make out,  I created a SFML folder in my C: drive (C:\SFML\SFML 2.0) and I compiled the SFML source using Cmake(both Debug and Release). Though I did generate some files(sfml-graphics.dll ,etc) the tutorial didn't mention to use them.

Though I could set up SFML with Visual Studio 12(followed this tut:),
I have never successfuly done that for Code::Blocks.

114
General / Re: Game window not working
« on: August 09, 2013, 08:44:10 am »
Maybe if you posted why the code doesn't compile we might be able to help you. Just saying code doesn't compile without any error message of any sort won't help you out.

The compiler down't display any error message. As soon as I hit Run, the SFML window appeares and then another dialog pops up telling that mysfmlprogram.exe has stopped working and windows is looking for a solution. After that nothing happens and process terminates with status -1073741819.

115
General / [Solved]Game window not working
« on: August 08, 2013, 05:51:46 pm »
Hello

I installed SFML 2.0 after a lot of struggle in Code::Blocks with the MinGW 4.7.2 compiler. When I compile the follwoing code, it compiles and runs flawlessly:

#include <SFML/Graphics.hpp>
#include <iostream>

const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
const int WINDOW_BPP = 32;
const char *WINDOW_CAPTION = "MY_SFML";

int main()
{
    sf::RenderWindow Window;
    Window.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP),
                  WINDOW_CAPTION, sf::Style::Close);

    while(Window.isOpen())
    {
        sf::Event Event;

        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    {
                        Window.close();
                    } break;
                case sf::Event::KeyPressed:
                    {
                        if(Event.key.code == sf::Keyboard::Escape)
                        {
                            Window.close();
                        }
                    } break;
            }
        }

        Window.display();
    }
}
 
But if i am trying to display a circle or rectangle(as in the following code), then the code doesn't compile:

#include <SFML/Graphics.hpp>

const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char *WINDOW_CAPTION = "MY_SFML";

const float CIRCLE_RADIUS = 100.0f;

int main()
{
        system("cls");

        sf::RenderWindow GameWindow(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT),
                WINDOW_CAPTION, sf::Style::Close);

        sf::CircleShape Circle(CIRCLE_RADIUS);
        Circle.setFillColor(sf::Color::Yellow);

        while(GameWindow.isOpen())
        {
                sf::Event GameEvent;

                if(GameWindow.pollEvent(GameEvent))
                {
                        if(GameEvent.type == sf::Event::Closed)
                        {
                                GameWindow.close();
                        }

                        GameWindow.clear();
                        GameWindow.draw(Circle);
                        GameWindow.display();
                }
        }

        return 0;
}

So where's the problem?

Thanks

Pages: 1 ... 6 7 [8]