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

Author Topic: My Game is lagging  (Read 6656 times)

0 Members and 1 Guest are viewing this topic.

domcsidd

  • Newbie
  • *
  • Posts: 9
    • View Profile
My Game is lagging
« 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

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: My Game is lagging
« Reply #1 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 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.


domcsidd

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: My Game is lagging
« Reply #2 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 .  :)

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: My Game is lagging
« Reply #3 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.
« Last Edit: May 12, 2013, 06:58:11 pm by gostron »

domcsidd

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: My Game is lagging
« Reply #4 on: May 12, 2013, 07:08:20 pm »
Ok , I will do that . But how can i "making it time dependent."

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: My Game is lagging
« Reply #5 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

gostron

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: My Game is lagging
« Reply #6 on: May 12, 2013, 07:20:16 pm »
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

domcsidd

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: My Game is lagging
« Reply #7 on: May 12, 2013, 07:23:26 pm »
Thank you very much .

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: My Game is lagging
« Reply #8 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++.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything