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

Pages: [1]
1
Graphics / Re: Problem with sf::Sprite
« on: June 12, 2012, 05:10:44 pm »
Solved.

The mistake was to create an object before initializing the window. I'm sorry: p  :-[ :-[

Thanks thePyro_13!!  ;)


2
Graphics / [Solved] Problem with sf::Sprite
« on: June 12, 2012, 04:36:39 pm »
Hello everyone,

I'm new in this forum and I got some problem with sf::Sprite. I'm trying to do a class called piece and one of his attributes is a sprite and a texture. This is the code I wrote in the class Piece.h.

#ifndef PIECE_H_
#define PIECE_H_

class Piece {
public:
        Piece();
        virtual ~Piece();

        sf::Texture p_texture;
        sf::Sprite p_sprite;
};


#endif /* PIECE_H_ */
 

And this is Piece.cpp

#include <SFML/Graphics.hpp>
#include <iostream>
#include "Piece.h"

using namespace std;

Piece::Piece() {
        if(!p_texture.loadFromFile("./Images/Pieza_Azul.png"))
        {
                cout << "Error." << endl;
        }

        p_sprite.setTexture(p_texture,true);
}

Piece::~Piece() {
        // TODO Auto-generated destructor stub
}
 

And this is the main.cpp

#include <SFML/Graphics.hpp>
#include "Pieces/Piece.h"
#include <iostream>
using namespace std;

int main() {
        Piece obj_piece;

        // Create the main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
        window.setVerticalSyncEnabled(true);
        window.setFramerateLimit(60);



        // Start the game loop
        while (window.isOpen())
        {
                // Process events
                sf::Event event;
                while (window.pollEvent(event))
                {
                        // Close window : exit
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                // Clear screen
                window.clear(sf::Color::White);
                window.draw(obj_piece.p_sprite);
                // Update the window
                window.display();
        }

        return 0;
}

When I start to compile the program, does not give any error during the compilation process, but when I try to run get an error:

not valid domains REMAIN!

In addition, the window look really weird things.

I wanted to comment if you can put a sprite in a class, I've tried in various ways, but it still fails. When I put a Sprite in a class and compile SFML window disappears instantly, and gives no errors in compilation or execution.

The question is, you should put a sprite in a class such as a character in order to have the sprite associated with that object? If yes the attribute must be private right?

regards

Yemlhalf

ps: Sorry if I made grammatical or lexical errors I have to improve my English: p

Pages: [1]
anything