SFML community forums

Help => System => Topic started by: domcsidd on May 12, 2013, 05:39:41 pm

Title: My Game is lagging
Post by: domcsidd on May 12, 2013, 05:39:41 pm
Hi ! I don't know , why lagging my game ?
Here is the project : https://www.zeta-uploader.com/1238773236 (https://www.zeta-uploader.com/1238773236)
Title: Re: My Game is lagging
Post by: gostron on May 12, 2013, 06:12:52 pm
Hi,

I'm probably gonna answer before anyone else does, but this is not the right way to procede I fear.

This topic http://en.sfml-dev.org/forums/index.php?topic=5559.0 (http://en.sfml-dev.org/forums/index.php?topic=5559.0) will help you understand how to resolve your problem.

You have to search by yourself and try and debug on your own before asking others to dig in your code.

The simplest thing is to try and comment out some parts of your code and/or to put a clock to see which part takes time.

Once you've got something isolated you can try and resolve it and if you can't, we'll be more than happy to try and understand why some lines take time.

Another way would be to try and create a minimal code that replicates the issue for us to see quickly what is the issue. Everything is explained in the link I put before.

Some developers use profilers to try and find what poses a problem at a lower level.

Title: Re: My Game is lagging
Post by: domcsidd on May 12, 2013, 06:40:04 pm
Thanks the answer , i tried to commented parts , but it haven't helped so far . I 'm beginner in c++ and sfml programming . Yes you 're right . But i don't know what the problem exatly is ? I have written an other sfml program too , but it works fine . I think it is not a memory problem , because i have big RAMS , and it isn't an giant program , so i pasted the whole source. Sorry , but my english is not the best .  So , please help me to understand the problem .  :)
Title: Re: My Game is lagging
Post by: gostron on May 12, 2013, 06:55:41 pm
I took a look at your code and my first reaction was.. OMG

Understanding another's code is not the simplest thing but you make it a lot harder !

First you need to use object in C++ and not put everything in the main or in the file main.cpp

Your indenting is not the simplest either.

Considering all that, I'd consider using events differently.

Since you get the keyboard status in each frame, you shouldn't put verifications INTO the pollEvent loop, but outside, and making it time dependent.

Finally, you should try and follow a few basic tutorials about C++ to write it differently, I'm not really surprised by the fact you're managing to find where the problem is from with that code.

Hope I'm not being too harsh but people can correct me if I'm wrong.
Title: Re: My Game is lagging
Post by: domcsidd on May 12, 2013, 07:08:20 pm
Ok , I will do that . But how can i "making it time dependent."
Title: Re: My Game is lagging
Post by: AlexAUT on May 12, 2013, 07:18:59 pm
Ok , I will do that . But how can i "making it time dependent."

Here is a good article about this topic (http://www.koonsolo.com/news/dewitters-gameloop/). But you should learn something about the basics of c++ first...


AlexAUT
Title: Re: My Game is lagging
Post by: gostron on May 12, 2013, 07:20:16 pm
http://www.sfml-dev.org/tutorials/2.0/system-time.php (http://www.sfml-dev.org/tutorials/2.0/system-time.php)
would be a good way to start

In the main loop while(window.isOpen())
you get the time the last frame took, and you use this frameTime to multiply every change in position.
this is a classic way of handling positions and you should be able to find many good tutorials with Google
Title: Re: My Game is lagging
Post by: domcsidd on May 12, 2013, 07:23:26 pm
Thank you very much .
Title: Re: My Game is lagging
Post by: zsbzsb on May 12, 2013, 10:36:49 pm
Quote
I 'm beginner in c++ and sfml programming

If you are a beginner in C++ I highly recommend you take 2-3 months at least to learn C++ from a good book. Make small projects, stuff you can't get attached to very much and learn to write it correctly. Learning C++ from the internet while trying to make a game will get you caught up in the small little details of games and will cause you to not learn how to code properly. Once you get proper C++ coding down then take on a small game such as a clone of pacman, pong, ect... To start to get the idea of how a game is made. Making games is not something you can sit down and pick up over night, especially if you do not already know C++.