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 - eXpl0it3r

Pages: 1 ... 626 627 [628] 629 630 ... 720
9406
General discussions / Re: Dev-C++?
« on: October 22, 2012, 09:21:05 pm »
Dev-CPP is used by people who don't know it is outdated
And nobody read my post...

Dev-C++ is again in development (latest release is from 2nd October 2012) and since Dev-C++ is only an IDE and the 'core' is MinGW, it doesn't really matter if feature XY isn't the newest one...

What IDE you like or not is a completly other and useless discussion...

9407
Graphics / Re: Cant draw Tilemap with Class
« on: October 22, 2012, 08:57:41 pm »
Quote
I'd suggest a 1 tab = 4 spaces translation
Done :)
You're awesome! :)

Btw would it be possible to install the tapatalk mod, so one could read the forum easily on the phone?

9408
Window / Re: Drawing/Displaying sprites from another function
« on: October 22, 2012, 05:25:55 pm »
You should also put event polling at the end of the loop, that way if you close the window it won't keep on drawing, displaying and so on with a closed window.
That's more of a detail and it will mostly work the other way around too, the draw calls will just have no effect. ;)

9409
Graphics / Re: Cant draw Tilemap with Class
« on: October 22, 2012, 04:05:51 pm »
The mod doesn't allow to change the tab width through the admin panel. I have to add a line of code to the mod sources.
I guess/hope shouldn't be that hard...
I'd suggest a 1 tab = 4 spaces translation, which is what you mostly get as default setting in many editors.

And if I change the mod settings so that tabs are not translated to spaces, I lose line breaks :(
Bad mod! :P

9410
Graphics / Re: Cant draw Tilemap with Class
« on: October 22, 2012, 03:41:26 pm »
The whole problem was that you never created the render texture, thus it had a size of (0,0) and obviously nothing gets displayed...

Here's a fully working code. I cleaned up your strange indentation (now uses tabs) and removed the useless vector thingy. I mean there's no sense in reading it into one vector if you're going to draw it once to a render texture and then use that texture. You don't need the sprites objects later. I also fixed the possibility that the program crashes if the map file doesn't exists and a few other minor things...
You should really stop just trying to 'solve' things by programming and rather sit down and think about what you're doing. ;)

Edit: Hmm the indentation doesn't look that nice now either...
@Laurent: Is it really necessary that one tab gets translated to 8 spaces? :O

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

class Map
{
public:
        int map_x, map_y;       // width, height
        int map[100][100];      // Maparray
        sf::Texture textur;     // Texture from Image Tilemap
        sf::RenderTexture rMap; // Texture sMap
        sf::Sprite sMap;        // Mapsprite

public:

        Map() :
                map_x(0),
                map_y(0)
        {
                // Loading Texture
                if(!textur.loadFromFile("boden.png"))
                {
                        std::cout << "boden.png konnte nicht geladen werden!\n";
                }
        };

        // Just tilesize
        static int getTile()
        {
                return 32; // 1 Tile = 32 Pixel
        }

        void loadMap(const char *filename)
        {
                // Load map from filename, first line width and height, other lines: id of tile
                int loadCounterX = 0, loadCounterY = 0;
                std::ifstream file(filename);

                // Exit if file doesn't exist
                if(!file.is_open())
                {
                        std::cout << "Couldn't open '" << filename << "'. Aborting." << std::endl;
                        return;
                }

                file >> map_x >> map_y;
                while(!file.eof())
                {
                        file >> map[loadCounterX][loadCounterY];
                        loadCounterX++;
                        if(loadCounterX >= map_x)
                        {
                                loadCounterX = 0;
                                loadCounterY++;
                        }
                }

                // Create the off screen texture
                rMap.create(map_x*32, map_y*32);
                rMap.clear();

                // Create tiles
                for(unsigned int y = 0; y < map_y; ++y)
                        for(unsigned int x = 0; x < map_x; ++x)
                        {
                                sf::IntRect ir(map[y][x]*32, 0, 32, 32);
                                sf::Sprite sprite(textur, sf::IntRect(map[y][x]*32, 0, 32, 32));
                                sprite.setPosition(x*32, y*32);
                                rMap.draw(sprite);
                        }

                rMap.display();

                rMap.getTexture().copyToImage().saveToFile("test.png");
                sMap.setTexture(rMap.getTexture(), true);
        }

        // get Mapsprite
        const sf::Sprite& getSprite() const
        {
                return sMap;
        }

        //draw Mapsprite on target
        void draw(sf::RenderTarget& target) const
        {
                target.draw(sMap);
        }
};

int main()
{
        // Create window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
        // Limit framerate
        window.setFramerateLimit(60);

        Map mm;
        mm.loadMap("map1.txt");

        while(window.isOpen())
        {
                // Event handling
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                                window.close();
                }

                // Render
                window.clear();
                mm.draw(window);
                window.display();
        }
}
 

9411
Graphics / Re: Cant draw Tilemap with Class
« on: October 22, 2012, 02:26:34 pm »
You should provide a minimal and complete example and include a map file, so we could test everything... ;)

9412
This is great! :)

Thanks a lot!

9413
Graphics / Re: Cant draw Tilemap with Class
« on: October 22, 2012, 01:27:38 pm »
I though I knew that problem from somewhere (spieleprogrammierer)... ;D

The problem I think lies in the call sMap.setTexture(rMap.getTexture());, because you set a new texture but you don't change the size of the texture rectangle, so you actually don't cut out anything from the render texture. (I think Schorsch already tried to point you in that direction).
Try changing it to: sMap.setTexture(rMap.getTexture(), true);
Also you shouldn't return a copy of the sprite when calling drawMap() but instead use a const reference. ;)

9414
SFML projects / Re: SFMLUploads.org - Relaunch!
« on: October 22, 2012, 01:15:07 pm »
There was a problem with the SQL queries which lead to different problems, one was for instance that you could not create a new pastie.
Those bugs have now been resolved!


If you experience any problems, please report them here. It's impossible for me to test everything to its last detail and since the code wasn't originally written by me, I can't connect all the dots yet.
In near future I might rewrite most of it and adapt it to a better style which should also be easier to maintain. ;)

9415
Window / Re: Drawing/Displaying sprites from another function
« on: October 22, 2012, 09:27:24 am »
Like I said learn C++ first because you used a pointer and not a reference...

Also you should always separate logic & drawing and the drawing block should always be: clear, draw, display

9416
General discussions / Re: Dev-C++?
« on: October 22, 2012, 09:08:58 am »
If you want to use it at least use the most recent one from 2nd October 2012, you can grab it from here. ;)

9417
Graphics / Re: Transparent windows.
« on: October 22, 2012, 08:08:15 am »
A similar question has been asked not long ago. Maybe you find the discussion again...
SFML doesn't provide functionalities for transparent windows, but you might be able to get it with some OpenGL code.

9418
Graphics / Re: Where to put renderwindow
« on: October 22, 2012, 08:04:57 am »
I adivse you to read some more about OOP, because your current code doesn't make any sense... ;)

9419
General discussions / Re: Dev-C++?
« on: October 22, 2012, 08:01:53 am »
If you mean the original Dev-C++, then probably not...
But there's been some guy that took on the project and created a newer unoffical version, maybe someone uses it...

9420
Just read the official tutorials, it's all explained there... ::)

-l-lsfml-graphics
-lsfml-graphics

What could be the mistake here... :O

Also I strongly advise you against the use of SFML 1.6, it's over 2y old, contains quite a few nasty bugs and lacks a lot of new features.

Pages: 1 ... 626 627 [628] 629 630 ... 720