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

Author Topic: SFML Complete Game Tutorial  (Read 57887 times)

0 Members and 1 Guest are viewing this topic.

Razzeeyy

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML Complete Game Tutorial
« Reply #75 on: January 27, 2012, 12:36:51 am »
Serapth, oh yeah... that was stupid confuse about coordinates...
But I lack at math knowledge at this point :P so I can't model an elegant collision response model... Maybe you can advice me what to read on this topic?

BTW: If you want to take a look at current state of my project https://github.com/Razzeeyy/Re-tank-dev
The code organization (mostly) "inspired" by your great tutorial :)))

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #76 on: January 27, 2012, 03:36:05 pm »
Quote from: "Razzeeyy"
Serapth, oh yeah... that was stupid confuse about coordinates...
But I lack at math knowledge at this point :P so I can't model an elegant collision response model... Maybe you can advice me what to read on this topic?

BTW: If you want to take a look at current state of my project https://github.com/Razzeeyy/Re-tank-dev
The code organization (mostly) "inspired" by your great tutorial :)))



Ill take a look through your code a bit later, I'm absolutely swamped right now.


But as for learning the required math, it's hard to be The Khan Academy ( http://www.khanacademy.org/ ).  They have video tutorials on EVERYTHING, and the few ive watched were extremely well done.  About 10x better than my OAC level math teachers, who I have a sneaking feeling didn't know shit.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
SFML Complete Game Tutorial
« Reply #77 on: February 03, 2012, 02:24:04 am »
Just wondering how to make an Array of sprites using the code for making sprites from the tutorial.  I'm setting up A* for path finding and need an array of sprites that can fill the map and not make more than I need.


Also do you happen to have a reusable Text Object making system yet?
I'm needing the same idea with the text objects.


I ran into an annoying problem when trying to use the static libs.  No matter what I did I kept getting errors any time I tried to use them and I had the SFML_STATIC in the right area. :(
I have many ideas but need the help of others to find way to make use of them.

Razzeeyy

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML Complete Game Tutorial
« Reply #78 on: February 05, 2012, 02:18:07 pm »
Quote from: "StormWingDelta"
Just wondering how to make an Array of sprites using the code for making sprites from the tutorial.  I'm setting up A* for path finding and need an array of sprites that can fill the map and not make more than I need.


Once I was making a sort of tile painter, and I used a map like that
std::map < sf::Vector2f, myObj* >

where is the sf::Vector2f was denoting the position of the object and the myObj* is a pointer to the object itself.

And then I just cycled trough the map and draw objects.

But I think it's messy solution... (but at least it works :P)
Maybe other people can offer a better way

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6267
  • Thor Developer
    • View Profile
    • Bromeon
SFML Complete Game Tutorial
« Reply #79 on: February 06, 2012, 07:17:57 pm »
Quote from: "Razzeeyy"
Maybe other people can offer a better way
If anyhow possible, I'd probably use a myObj instead of myObj*. This is problematic for polymorphic objects, but one approach is to use smart pointers like std::unique_ptr or specialized containers like boost::ptr_map...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #80 on: February 06, 2012, 07:54:42 pm »
Quote from: "Nexus"
Quote from: "Razzeeyy"
Maybe other people can offer a better way
If anyhow possible, I'd probably use a myObj instead of myObj*. This is problematic for polymorphic objects, but one approach is to use smart pointers like std::unique_ptr or specialized containers like boost::ptr_map...



I second this.  Actually unique_ptr is one of the areas I am going to address in the next chapter, I intend to replace the currently naked pointer used in the caching system.  Additionally, depending on your level setup, but if the size is known in advance, a good ole fashion 2D array might be your best bet.  Has minimally less overhead than using a map and is slightly less complicated.  Of course, your sizes are fixed in this situation.

@StormWingDelta, what are the errors you are receiving if you use static.

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
SFML Complete Game Tutorial
« Reply #81 on: February 22, 2012, 04:41:56 pm »
Quote from: "Serapth"
Quote from: "Nexus"
Quote from: "Razzeeyy"
Maybe other people can offer a better way
If anyhow possible, I'd probably use a myObj instead of myObj*. This is problematic for polymorphic objects, but one approach is to use smart pointers like std::unique_ptr or specialized containers like boost::ptr_map...



I second this.  Actually unique_ptr is one of the areas I am going to address in the next chapter, I intend to replace the currently naked pointer used in the caching system.  Additionally, depending on your level setup, but if the size is known in advance, a good ole fashion 2D array might be your best bet.  Has minimally less overhead than using a map and is slightly less complicated.  Of course, your sizes are fixed in this situation.

@StormWingDelta, what are the errors you are receiving if you use static.


Don't remember the errors off hand so I'll have to look them up the next time I try to build my pong project with static libs.

In the meantime I've noticed a number of annoying things with the pong game that just seem off to me.

The first one is very noticeable in my version and that's when I go to the play state and than come out of it and go back into it.  The art and/or sprites don't load or they just aren't on the screen for some reason when I go back into the play state. It's like the game sprites are still in play state while the rest of the game isn't.

Next would be the AI tends to get stuck in walls when it gets too close and the reflection kicks in. The same thing happens to the player as well.

The other thing I've noticed is that any time I try to make changes to the game class I end up with more errors than I'd like. They all have something to do with it griping about incorrect declarations of some kind or another.

Aside from those things it is very good tutorial. :) Also when is part 10 coming out? :?:
I have many ideas but need the help of others to find way to make use of them.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #82 on: February 22, 2012, 10:31:43 pm »
Yeah, many of the annoyances should be addressed in the next chapter, whenever that is. :)

Quote
The other thing I've noticed is that any time I try to make changes to the game class I end up with more errors than I'd like.


There should be no real issues in changing the game code, so next time this happens, post the error that occurs and the code you added/changed.



As to disappearing sprites, they aren't actually disappearing, they are moving... very very very far.  The game no longer updates when showing the Menu, but SFML does, and this is where the "bug" is coming from.  Essentially each frame we are getting the elapsed time since the last frame which we then use to normalize movement the next frame.  The code assumes this number is always going to be a tiny fraction of a second, but this isn't true if we do something between drawing frames ( like hitting a break point or showing the menu ).


Any easy crude work around is to discard any deltas over a certain threshold.

So, in GameObjectManager, locate:
Code: [Select]

void GameObjectManager::UpdateAll()
{
std::map<std::string,VisibleGameObject*>::const_iterator itr = _gameObjects.begin();
float timeDelta = Game::GetWindow().GetFrameTime();
...


Add the line:
Code: [Select]

if(timeDelta > 0.1f) timeDelta = 0.0f;


Which basically says if more than 1/10th a second occurred between updates, 0 out the timeDelta, which will effectively cause no movement this update.  If there is a way to "reset" GetFrameTime() or to pause it in general, that would be a cleaner solution.

That will fix the disappearing sprite issues.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6267
  • Thor Developer
    • View Profile
    • Bromeon
SFML Complete Game Tutorial
« Reply #83 on: February 24, 2012, 05:55:07 pm »
Quote from: "Serapth"
Yeah, many of the annoyances should be addressed in the next chapter, whenever that is. :)
I don't know whether it's a good idea to introduce bugs in chapters and fix them later. For some topics this can be meaningful because of the learning effect, but doing this too much gives the impression that your tutorial is incorrect. Maybe you had better fix them in the original code (given this doesn't complicate it as hell).

Quote from: "Serapth"
If there is a way to "reset" GetFrameTime() or to pause it in general, that would be a cleaner solution.
GetFrameTime() is a relict, it has been removed from SFML. You should use sf::Clock directly. By the way, even though this is out of scope for the tutorial, I have developped a StopWatch class which can be paused.

And StormWingDelta: If you only refer to the last sentence in a post, please only quote that last sentence. Full quotes are unnecessary and make the thread unreadable. Since the original post is just above, a quote is generally not required to understand the discussion.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #84 on: February 25, 2012, 12:54:33 am »
Quote from: "Nexus"
don't know whether it's a good idea to introduce bugs in chapters and fix them later. For some topics this can be meaningful because of the learning effect, but doing this too much gives the impression that your tutorial is incorrect. Maybe you had better fix them in the original code (given this doesn't complicate it as hell).



... yeah... intentional....  [[Wheres the whistle innocently gif???]]  Truth of the matter is, the way I did things, fixing a bug early on creates an absolute friggin nightmare for me, especially because I zip and share a compiled form of each chapters project, so if I change something in chapter 2, I need to propogate the change in chapters 2 thru 10, create and upload 9 8+ MB zips, then change all the source code examples where I expanded upon the code previously.

Quote
GetFrameTime() is a relict, it has been removed from SFML. You should use sf::Clock directly. By the way, even though this is out of scope for the tutorial, I have developped a StopWatch class which can be paused.


Tutorial is based on 1.6, where I though GetFrameTime was still the recommended way?  Trying to keep things the "out of the box" way as much as possible.  Got a link to your class, at the very least it would be useful to people reading this thread.

EDIT:  Nevermind, re the link, didnt see your sig while replying.

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #85 on: February 27, 2012, 06:26:38 pm »
I just realized I made a small, but glaring omission wayyyyyyy back in part two!.  Although I talked about pre-compiled headers and the use of stdafx, I forgot to include them in my write up!  This means you wouldn't have them if you weren't using the downloadable project.


This doesn't really sound like a big deal, until you realize that this is where all of the SFML includes are!   This explains some of the questions and problems people had early on and why downloading the full project fixed things.


Ooops.   :oops:


So, I've addressed this mistake so people following along in the future won't have this problem.  If you've run through the tutorial and ran into this problem...  this is why.  Considering #includes are one of the more confusing topics for beginner C++ programmers, this was a majorly stupid mistake on my behalf.  My apologies.

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
SFML Complete Game Tutorial
« Reply #86 on: March 05, 2012, 08:13:33 pm »
Has anyone successfully converted the tutorial over to SFML2?

I have, but with a couple of strange issues.  In Debug I get an exception in SFML at:

Code: [Select]
void MutexImpl::Lock()
{
    EnterCriticalSection(&myMutex);
}


Similar error to some bad practices from me last year:
http://www.sfml-dev.org/forum/viewtopic.php?t=5654
(Nexus will be glad to hear I'm educating myself out of this!)


It seems to run in Release or from the .exe, but behaves very jittery indeed.

I also have another little project that uses some of the guts of Serapth's code along with the simple Image Manager tutorial on the Wiki. That too has these issues, better in Release than Pong, but still some odd things happen that don't make a lot of sense.
{much better code}

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #87 on: March 09, 2012, 08:53:28 pm »
Quote from: "Jove"
Has anyone successfully converted the tutorial over to SFML2?

I have, but with a couple of strange issues.  In Debug I get an exception in SFML at:

Code: [Select]
void MutexImpl::Lock()
{
    EnterCriticalSection(&myMutex);
}


Similar error to some bad practices from me last year:
http://www.sfml-dev.org/forum/viewtopic.php?t=5654
(Nexus will be glad to hear I'm educating myself out of this!)


It seems to run in Release or from the .exe, but behaves very jittery indeed.

I also have another little project that uses some of the guts of Serapth's code along with the simple Image Manager tutorial on the Wiki. That too has these issues, better in Release than Pong, but still some odd things happen that don't make a lot of sense.



Hi Jove, read back earlier in the thread and there were a few people that successfully ported to 2.0, although I haven't really tried yet.

There is nothing in the project that should cause that error however.   If you are still searching for a needle in a haystack at this point, strip down your project  ( I do this so often I wrote a tool Project Cleaner to do that job for me ), zip it up and send me a link and I will see if I can find your issue.

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
SFML Complete Game Tutorial
« Reply #88 on: March 10, 2012, 11:49:18 am »
Thanks Serapth, PM sent.

If we solve this I'll post the solution, however shameful it may be ;)
{much better code}

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
SFML Complete Game Tutorial
« Reply #89 on: March 10, 2012, 03:47:37 pm »
Quote from: "Jove"
Thanks Serapth, PM sent.

If we solve this I'll post the solution, however shameful it may be ;)



I think I know your problem.  You need to use the same build settings on your SFML library compile as you do for your game project.  For example, if you compile the debug release to use multithread debug, you need to do the same when you build sfml.  Also, in your release version, you are linking to the static libraries. ( -s ), which is a no no with the settings you have.

 

anything