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

Author Topic: I need help with the FPS system and with correct drawing of objects  (Read 3631 times)

0 Members and 2 Guests are viewing this topic.

vasyaslife

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
1) Implementation of FPS in games (FPS) How it works? What's the best way? If you use just a cycle and then drawing and calculation of properties of objects then the speed of the game will depend on the performance of your PC. (I use the time between 1 cycle  tact. After that i multiply all the calculations but this method has many disadvantages.)  8)

2) How to draw objects window, if I change the screen resolution?
My method: all graphics has 1920x1080
I divide the selected resolution (K = selected height / 1080), then I use the scale in SFML reduces the width and height of the window after recreates the selected screen resolution. I think - this is not the right solution, because this method at work show lags (probably it connected with a lack of FPS system)  ::)




dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: I need help with the FPS system and with correct drawing of objects
« Reply #1 on: March 15, 2014, 05:53:42 pm »
1) Implementation of FPS in games (FPS) How it works? What's the best way? If you use just a cycle and then drawing and calculation of properties of objects then the speed of the game will depend on the performance of your PC. (I use the time between 1 cycle  tact. After that i multiply all the calculations but this method has many disadvantages.)  8)
You're on the right track about PC performance being a factor! I'd recommend reading this article.

Though, other people on the forum tend to link to this one. They're on the same topic, it's been a while since I've read either, so I can't remember the specific differences. They're both good articles/authors though!

2) How to draw objects window, if I change the screen resolution?
My method: all graphics has 1920x1080
I divide the selected resolution (K = selected height / 1080), then I use the scale in SFML reduces the width and height of the window after recreates the selected screen resolution. I think - this is not the right solution, because this method at work show lags (probably it connected with a lack of FPS system)  ::)
You may want to read up on using a sf::View.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: I need help with the FPS system and with correct drawing of objects
« Reply #2 on: March 15, 2014, 06:45:27 pm »
i don't think sf::View has anything to do with screen size (except for changing the view size itself).
i usually consider the whole screen going from 0 to 1 in size, in both axes. then you put the sprites where you want from 0 to 1. in the end, just multiply the sprite position by the actual screen resolution selected.
so, you can change screen resolutions and everything will be kept in its place.
just note that this doesn't change the sprites size. you'll have to size them manually (you can use a similiar approach).

OR you can create a renderTexture, draw everything to it, resize it to fit your resolution, and then draw() it to the window.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

vasyaslife

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: I need help with the FPS system and with correct drawing of objects
« Reply #3 on: March 16, 2014, 05:35:12 am »
Hm, ok. I will read this.
But what do you think about my method with  the screen resolution. Is it right? I saw a lot of games and I played with their  the screen resolution system after that i wrote my method.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
i don't think sf::View has anything to do with screen size (except for changing the viewsize itself).
Ehrm the view is the "window", it defines what can be seen from the whole "scene". Of course the final mapping/logic is a bit a different topic and the percentage mapping is certainly a goid way. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: I need help with the FPS system and with correct drawing of objects
« Reply #5 on: March 17, 2014, 06:18:25 pm »
i may be wrong, but i think the view is more like a cam, since you can have multiple views in a single window. it may or may not be the window size. also you could have empty margins on the window (to use as GUI or something) that wouldn't be part of the view, so i still don't think is a good idea to consider a view as your whole window.

But what do you think about my method with  the screen resolution. Is it right?
i don't think it is wrong. it's basically the same i suggested, but you use 1920x1080 as a default resolution, and i use 1x1. i do it like that just to make easier calculations (and previews in my mind).
Visit my game site (and hopefully help funding it? )
Website | IndieDB

vasyaslife

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: I need help with the FPS system and with correct drawing of objects
« Reply #6 on: March 19, 2014, 05:26:23 pm »
I worked with my method and i saw the other problem.
I have 2 image:
Background 1920x1080
Human 118X112

        float xInMap=0.055, yInMap=0.775; //Human's X, Y
   float xResolution = 1200, yResolution = 510; //Selected resolution
   float K = yResolution/1080;

   sprite.setTextureRect(IntRect(0,0,1920,1080)); //My background
   sprite.setPosition(-0.01*xResolution,0); //Background Position

   sKyb.setTextureRect(IntRect(0, 0, 118, 112)); //My human
   sKyb.setPosition(xInMap*xResolution, yInMap*yResolution); //Human position

   sKyb.setScale(K, K);
   sprite.setScale(K, K);

   
   float xImage = xInMap*xResolution, yImage = yInMap*yResolution; //Position for drawing


   RenderWindow app(VideoMode(xResolution, yResolution), "Test Window");
In one situation human stay at one place(in background). Example: stands at the door, which drawed in background. Then i changed resolution and after that the human didn't stay at the door :(

I know where is the problem but i don't know how to fix it:
The problem in the Scale. When i scaled background, i changed the position of door.
But plz don't advise me that i must work with image where human are with size 1920x1080 (it's load pc a lot) and don't advise me that i must work with door separately coz in future i need to work with background.
Hope that you understand me, coz i lost my brain an hour ago and i sure that i wrote nonsense  ;D
This picture help you to understand me
in this image i used 1280x720


in this image i used 900x800 (it's not the one of resolutions where i saw the problem)

vasyaslife

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: I need help with the FPS system and with correct drawing of objects
« Reply #7 on: March 20, 2014, 12:52:42 pm »
Upd. I fix that :)
My method - i have 2 type of coordinates
The fist - x,y in game (same background size)
The second - X,Y when i draw all objects (X = x*K)