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

Author Topic: SFML Window not showing!!!  (Read 36541 times)

0 Members and 2 Guests are viewing this topic.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #60 on: December 25, 2011, 09:13:02 pm »
Code: [Select]

sf::Sprite::SetSmooth(false);



You could have checked the documentation to see what Anata meant, or searched the forums (at the top of the page under "SFML forums"). It should take less time to do that than wait for an answer. By the way, in SFML 2.0 smooth is false by default.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #61 on: December 25, 2011, 10:10:45 pm »
I can't see sf::SetSmooth in sfml 2.0 .  And if its default, then whyre you telling me to set it to false if its already there? Im confused..

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #62 on: December 26, 2011, 12:31:43 am »
You're using SFML 1.6.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #63 on: December 27, 2011, 05:21:51 am »
Nope. I'm using SFML 2.0 because i use sf:PollEvent and it works. Also, I use another function thats in SFML 2.0. So i use SFML 2.0...

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #64 on: December 27, 2011, 01:04:06 pm »
Huh, I thought I saw sf::Sprite::SetImage() somewhere.... Maybe you've got the parameters of SetSubRect() wrong somehow and you're setting a subrect which doesn't exist completely in the image you loaded? When I do that I get a sort of cyan color, but it might be different from machine to machine. Also, in SFML 2.0, you use sf::Texture and sf::Sprite::SetTexture().

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #65 on: December 27, 2011, 07:18:31 pm »
Yep i use sf::Texture and sf::SetTexture too. So whatès my problem with the image flickering to black and then normal and then black...?

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #66 on: December 27, 2011, 08:52:39 pm »
Try drawing the image without SetSubRect(). If it's okay, the problem is probably with the parameters of SetSubRect(), and if you can't find the problem, show me the code and I'll try to find it.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #67 on: December 27, 2011, 09:06:56 pm »
Without the subrect function, it simply shows the whole spritesheet, no flickering of black thing. The flickering only happens when its animated(using subrect).

Heres my whole program code:
Code: [Select]



#include <SFML/Graphics.hpp>



int main()
{

    sf::VideoMode vmode(800,600,32);
    sf::RenderWindow Window(vmode, "Animation Training");


    sf::Texture texture;
    texture.LoadFromFile("Walker.png");
    sf::Sprite sprite;
    sprite.SetTexture(texture);
    int frame = 0;
    int frame2 = 0;
    sf::Clock clock;



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

        while(Window.PollEvent(Event))
        {
            if(Event.Type == sf::Event::Closed || sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
            {
                Window.Close();
            }
        }

        Window.Clear(sf::Color::Cyan);

        if(clock.GetElapsedTime() >= 100)
        {
            sprite.SetSubRect(sf::IntRect(frame * 68,frame2,68,68));
            ++frame;

            if(frame > 5)
            {
                frame = 0;
                ++frame2;

            }
            if(frame2 > 5)
            {
                frame2 = 0;
            }
            clock.Reset();


        }


        Window.Draw(sprite);


        Window.Display();






    }





    return 0;
}


Oh yes and btw the whole sprite sheet is 340 by 340(in pixels).  And theres 5 columns and 5 rows of images(frames) in the sprite sheet. And frame2 is for when the subrect "moves" to the next row so i increment it by 1 when frame is greater then five and then when frame2 reaches the last frame in the last row and frame also reaches the last image in the last row, they both reset to 0 which restarts the animation process.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #68 on: December 27, 2011, 09:17:09 pm »
You're moving the subrect down one pixel when frame is greater than 5; you need to move it down 68 pixels. In place of "frame2" if you write "frame2 * 68" it should be fine. Instead of the following:

Code: [Select]

if(frame2 > 5)
{
    frame2 = 0;
}



You can write "frame2 %= 5;". And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #69 on: December 27, 2011, 09:28:12 pm »
Wow. The animation just got so much better. It wasnt even properly walking lol now it is. However, it didnt solve the black flickering problem. So maybe i thought it was the spritesheet. But when i tried another one, there was no black but it was still flickering..

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #70 on: December 27, 2011, 09:30:49 pm »
Quote
And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.


Did you fix this?

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #71 on: December 27, 2011, 10:37:53 pm »
Code: [Select]


if(clock.GetElapsedTime() >= 100)
        {
            sprite.SetSubRect(sf::IntRect(frame * 128,frame2 *    128,128,128));
            ++frame;

            if(frame > 4)
            {
                frame = 0;
                ++frame2;

            }
            if(frame2 > 4)
            {
                frame2 = 0;
            }
            clock.Reset();


        }



This is my new code. I just changed the subrect parameters so now frame2 * 128 . Is there anything else i need to change?

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #72 on: December 27, 2011, 10:52:43 pm »
No, keep the "* 68", unless you changed the image size? Anyways, change "if(frame2 > 4){ frame2 = 0; }" to "frame2 %= 5;". You can check if frame is equal to 5 instead of if it's greater than 4; it's more readable.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #73 on: December 27, 2011, 11:14:00 pm »
its "* 128"  because remember i said i tried a new one and the black isnt there anymore but the animation still flickers? Well this one is bigger size so thats why. And i put " frame2 %= 5" and the animation messed up and the flickering was still there. And "frame2 == 5" is basically the same as "frame2 > 4" so.. Maybe it has to do with framerate or something?

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #74 on: December 28, 2011, 12:00:10 am »
"frame2 %= 5" should set frame2 to 0 when it reaches 5. I said to use '==' because it's more readable, not because it should fix anything. Make sure the image width and height are both 640 pixels.

 

anything