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

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

0 Members and 1 Guest are viewing this topic.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #75 on: December 28, 2011, 12:45:41 am »
Viruses, try adding one extra line of code:

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{

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

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #76 on: December 28, 2011, 04:47:59 pm »
Still flickering..

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #77 on: December 29, 2011, 05:10:29 am »
YES i FINALLY GOT IT NO FLICKERING A PERFECT ANIMATION! The problem was that i was actually drawing a subrect that was out of bounds of the spritesheet which meant it came up blank. Heres the updated code:

Code: [Select]

#include <SFML/Graphics.hpp>



int main()
{
    sf::RenderWindow Window(sf::VideoMode(800,600,32), "asdsad");

    sf::Clock clock;

    sf::Texture pic;
    sf::Sprite sprite;
    int frame,frame2;
    frame = 0;
    frame2 = 0;

    pic.LoadFromFile("SpriteSheet.png");

    sprite.SetTexture(pic);

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

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


        }

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

            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();

            }





            Window.Draw(sprite);

            Window.Display();








    }


    return 0;
}



So you see i put frame == 4 and frame2 == 4 instead of frame and frame2 == 5. So now i was drawing the frames in the actual sprite sheet, not a subrect beyond it. :D Thanks for all advice i extremely appreciate it!

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #78 on: December 29, 2011, 05:14:57 am »
Congratulations on solving your own error.  :D
Keep practicing and that will be very common.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #79 on: December 29, 2011, 02:33:11 pm »
Good job; that's what I was trying to tell you :).

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #80 on: December 29, 2011, 05:10:34 pm »
@Pyrius   Lol sorry shoulda looked at your advice more carefully :D   But thanks! Any ideas on how to make my OWN spritesheet?

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #81 on: December 29, 2011, 06:04:32 pm »
Well, the simplest way would be with paint, but there is also photoshop and a lot others.

By the way, I still recommend you to enable vertical sync, as it would limit the frame rate to the maximum supported by the monitor, avoiding useless processing and image tearing.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #82 on: December 29, 2011, 09:37:37 pm »
For a walking animation, this is helpful: http://www.manningkrull.com/pixel_art/tutorials/walking.asp. Don't copy it exactly, though, make your own character and follow the general idea. If you copy the legs pixel for pixel with different colors, you won't learn much.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #83 on: January 01, 2012, 07:35:08 pm »
Okay..Does anyone know of a site that has actually good sfml tutorials? Ive searched soooo much and all of the sites explain NOTHING.. I sort of know the basics but i still want to learn more about the sf namespace and such..and dont say documentation because its not like that explains it well.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #84 on: January 01, 2012, 08:04:29 pm »
The documentation works just well for myself. What do you expect?

By the way, there is a tutorial on making a complete game here: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #85 on: January 02, 2012, 01:36:02 am »
Ive already tried that website...

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #86 on: January 02, 2012, 03:00:51 am »
So, what happened? Why are you asking for other?

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #87 on: January 02, 2012, 09:13:44 pm »
Umm nvm.. I have a problem with coding. So, so far ive been coding in one file, the main.cpp . But ive noticed that when i was programming a game, it got way too confusing for one file. So then i made a class named Player. So now i had Player.h and Player.cpp . There were so much problems that i encountered. I want to organize it is that i will have the functions of Player all in that class. So Move() for example. Display() to display the player. But in order to display the player, you need a renderwindow object . Now this is where i got errors. When i put that Display() took an arguement of sf::RenderWindow()   (i did this arguement because in the main function i would pass my renderwindow object that id already made into the parameters) and therefor it would draw it. But in the header file of Player,   i dont know how to define a function that takes that arguement. I tried putting this:
Code: [Select]
 

void Display(sf::RenderWindow(sf::VideoMode(int,int,int), string);



Then in player.cpp i did this:

Code: [Select]


void Player::Display(sf::RenderWindow(sf::VideoMode(int,int,int), string);




The reason i put int int int and string is because the videomode takes those arguements and the string is for the title. So i got errors. Basically what i need is a way to organize my code into different files. Thats the whole thing. I just gave the above because its the main problem im having is putting variables of sf into the files..Thanks in advance!

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Window not showing!!!
« Reply #88 on: January 02, 2012, 09:21:02 pm »
That is some pretty fundamental C++ stuff you need to pick up here, people on this forum might be able to help you, but truth of the matter is you are asking the wrong people.

I would suggest you run through a tutorial or two, or pick up a book.  You need to get a bit more comfortable with the basics of C++ before you are really ready for SFML.  Try any of these resources, the free ones will get you started, although I highly recommend the C++ Without Fear book if you are willing to outlay some cash.  It's one of the best beginner books I've read, although I sped read it as a non-beginner.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #89 on: January 02, 2012, 09:58:40 pm »
Lol ive been through more than 73 tutorials, a book, and other websites and you saying i have to learn the basics.. This is probably one of those things that werent taught so.. and this has to do with sfml. the sf::RenderWindow() parameters..