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

Author Topic: Little Beginner problem  (Read 1261 times)

0 Members and 1 Guest are viewing this topic.

Pyrrha

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Little Beginner problem
« on: July 05, 2016, 02:52:50 pm »
Hey all,
I have some trouble importing a sprite from this code
#include <SFML/Graphics.hpp>

using namespace sf;


RenderWindow fen;
Texture lucina;
Sprite lucinasprite;


int main()
{
        lucina.loadFromFile("Lucina.png", IntRect(400, 300, 32, 32));
        lucinasprite.setTexture(lucina);
        //Création de la fenêtre
        RenderWindow fen(VideoMode(800, 600), "Learning SFML");
        fen.setPosition(Vector2i(0, 0));
        fen.setFramerateLimit(60);

        //Création d'un Rectangle
        RectangleShape rectangle(Vector2f(32, 32));
        rectangle.setFillColor(Color::Red);
        rectangle.setPosition(400, 300);

        //tant que la fenêtre est ouverte
        while (fen.isOpen())
        {

                Vector2i MousePos = Mouse::getPosition(fen);
                if (Mouse::isButtonPressed(Mouse::Left))
                {
                        // left mouse button is pressed: shoot
                        rectangle.setPosition(int(MousePos.x), int(MousePos.y));
                }
                //association des évènements de la fenêtre à un évènement sur une boucle
                Event WindowEvent;
                while (fen.pollEvent(WindowEvent))
                {
                        if (WindowEvent.type == Event::Closed)
                                fen.close();
                }
                fen.clear(Color::Cyan);
                fen.draw(rectangle);
                fen.draw(lucinasprite);

                fen.display();
        }

        return 0;

I have this error : Failed to create the texture, it's internal size is too high (BignumberxBignumber)
but my image is only 32x32 tall xD



And what should I put in this lucina.loadFromFile("Lucina.png", to aim a custom folder?

Pyrrha

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Little Beginner problem
« Reply #1 on: July 05, 2016, 03:23:27 pm »
Welp I removed this , IntRect(400, 300, 32, 32)); it seems to work for some reasons

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Little Beginner problem
« Reply #2 on: July 05, 2016, 06:03:27 pm »
That IntRect is to specify which part of the image to use for the texture. I'm presuming that the image is only 32x32 and isn't at least 432x332?  ;)

If the image is only 32x32, the rectangle you'd need is (0, 0, 32, 32) but since it defaults to the full image, you can just leave it off entirely, as you have experienced :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything