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

Author Topic: 2.0 Tutorials  (Read 7245 times)

0 Members and 1 Guest are viewing this topic.

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Tutorials
« on: October 04, 2011, 12:33:54 pm »
So, I think that the tutorials need updating, as the API has changed a bit for the next version.

I will update only the tutorials that contain source from the updated API, I will leave out the ones that are still working.

(I'll post the tutorials as replies to this one.)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #1 on: October 04, 2011, 01:19:39 pm »
Do it if you want, but don't forget that I'll update them soon. And I won't just update the source code, I'll rewrite almost all of them.
Laurent Gomila - SFML developer

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
Tutorial - Window - Handling Events
« Reply #2 on: October 04, 2011, 01:24:31 pm »
Deleted by Laurent, the "tutorial" was full of mistakes. It was confusing and didn't help at all.

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Tutorials
« Reply #3 on: October 04, 2011, 01:25:52 pm »
Quote from: "Laurent"
Do it if you want, but don't forget that I'll update them soon. And I won't just update the source code, I'll rewrite almost all of them.


Well, that might be the case, but until then, it's nice to have an alternative resource. As I'm reading through the tutorials, it won't hurt to post and updated version of them.

Besides, I have lots of free time today, and I'm planning to focus it on SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #4 on: October 04, 2011, 01:31:46 pm »
Quote
Code: [Select]
sf::Keyboard   keyboard   = sf::Keyboard();
sf::Mouse      mouse      = sf::Mouse();
sf::Joystick   joystick   = sf::Joystick();

Althought this code works, it is misleading. One is not supposed to instanciate these classes, all their functions are static.
Laurent Gomila - SFML developer

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Tutorials
« Reply #5 on: October 04, 2011, 01:45:17 pm »
Quote from: "Laurent"
Quote
Code: [Select]
sf::Keyboard   keyboard   = sf::Keyboard();
sf::Mouse      mouse      = sf::Mouse();
sf::Joystick   joystick   = sf::Joystick();

Althought this code works, it is misleading. One is not supposed to instanciate these classes, all their functions are static.


Thanks for the note, I updated the post and added the full source, which I forgot at first.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #6 on: October 04, 2011, 01:48:25 pm »
Quote
Code: [Select]
     int          JoystickX       = sf::Joystick::X;
      int          JoystickY       = sf::Joystick::Y;
      int          JoystickPOVX    = sf::Joystick::PovX;
      int          JoystickPOVY    = sf::Joystick::PovY;

This code isn't doing anything useful, sf::Joystick::X (and Y, PovX, PovY) are constants that must be used as axes identifiers in sf::Joystick functions.

Seriously, you shouldn't do that. You'll waste a lot of time, you'll make mistakes (I won't correct everything), and in a few weeks the official tutorials for 2.0 will be there.

There's already a thread that gathers all the API changes:
http://www.sfml-dev.org/forum/viewtopic.php?t=5343
Laurent Gomila - SFML developer

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Tutorials
« Reply #7 on: October 04, 2011, 03:07:46 pm »
Quote from: "Laurent"
Quote
Code: [Select]
     int          JoystickX       = sf::Joystick::X;
      int          JoystickY       = sf::Joystick::Y;
      int          JoystickPOVX    = sf::Joystick::PovX;
      int          JoystickPOVY    = sf::Joystick::PovY;

This code isn't doing anything useful, sf::Joystick::X (and Y, PovX, PovY) are constants that must be used as axes identifiers in sf::Joystick functions.

Seriously, you shouldn't do that. You'll waste a lot of time, you'll make mistakes (I won't correct everything), and in a few weeks the official tutorials for 2.0 will be there.

There's already a thread that gathers all the API changes:
http://www.sfml-dev.org/forum/viewtopic.php?t=5343


I have no idea how the joystick works, so I did the joystick lines randomly, with the closest new function I could find, but anyway I'm not going to do any more tutorials, since you're going to make them (probably better) soon anyway.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #8 on: October 04, 2011, 03:32:36 pm »
Quote
I have no idea how the joystick works, so I did the joystick lines randomly, with the closest new function I could find

So you wanted to help other users with incorrect random lines of code? :shock:
Laurent Gomila - SFML developer

Mind Calamity

  • Newbie
  • *
  • Posts: 10
    • View Profile
2.0 Tutorials
« Reply #9 on: October 04, 2011, 03:48:18 pm »
Quote from: "Laurent"
Quote
I have no idea how the joystick works, so I did the joystick lines randomly, with the closest new function I could find

So you wanted to help other users with incorrect random lines of code? :shock:


I just wanted to help, I was going to add a comment stating that those lines aren't necessarily correct, but I forgot, I'm going to add them now.

BTW - I believe most users don't really have Joystick (again a random guess), so I don't think that is going to be much of a problem, but then again I put a warning in the code.

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
Re: Tutorial - Window - Handling Events
« Reply #10 on: October 04, 2011, 04:50:17 pm »
Quote from: "Mind Calamity"
[...] when he presses the escape key :

OLD API:
Code: [Select]
while (App.GetEvent(Event))
{
    // Escape key pressed
    if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
        Running = false;
}

NEW API:
Code: [Select]
while (App.PollEvent(Event))
{
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape)))
App.Close();
}


This part confuses me, I'm pretty sure you just need to check the key code in the event structure, as you do in SFML 1.x.
I would rather write :
Code: [Select]
if (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Keyboard::Escape)
It seems to me that the purpose of sf::Keyboard::IsKeyPressed is to retrieve real-time inputs, outside the PollEvent loop, as you did with the sf::Input class in SFML 1.x.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #11 on: October 04, 2011, 04:57:50 pm »
Absolutely.

This thread is more confusing than it helps, it should probably be deleted.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
2.0 Tutorials
« Reply #12 on: October 04, 2011, 05:00:49 pm »
Ok, I didn't delete it but instead I removed the "tutorial" and locked the thread.

Sorry for OP, you wanted to help but these random lines of code were just confusing.
Laurent Gomila - SFML developer

 

anything