SFML community forums
Help => Graphics => Topic started by: vasyaslife on March 15, 2014, 05:12:53 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)
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) ::)
-
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 (http://www.koonsolo.com/news/dewitters-gameloop/comment-page-1/).
Though, other people on the forum tend to link to this one (http://gafferongames.com/game-physics/fix-your-timestep/). 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 (http://www.sfml-dev.org/tutorials/2.1/graphics-view.php) using a sf::View (http://www.sfml-dev.org/documentation/2.1/classsf_1_1View.php).
-
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.
-
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.
-
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. :)
-
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).
-
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
(http://s1.postimg.org/5cjwaijr3/image.png)
in this image i used 900x800 (it's not the one of resolutions where i saw the problem)
(http://s28.postimg.org/ld4axiwkt/image.png)
-
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)