This site requires JavaScript, please enable it in your browser!
Greenfoot back
Artyoum
Artyoum wrote ...

2014/8/10

How to keep up frame rates

Artyoum Artyoum

2014/8/10

#
I have recently created a basic scrolling world http://www.greenfoot.org/scenarios/12033 The issue I have is that when I run the scenario on my pc, the frame rate drops horribly and I am wondering how to maintain a good frame rate.
danpost danpost

2014/8/10

#
2500x2500 is a huge image. That would be 6'250'000 pixels of colors to iterate through. That is very costly, and in-efficient; especially considering how non-complex your background image is. You should make your red edges and blue lines of scrollable actor objects and just keep a flat gray background. Set the paint order so the Car, Player and Lable objects are painted on top of the lines and edges. That way you can dispense with scrolling the background image totally and just reposition the actors (which, for scrolling purposes, does not take any image manipulations). I guarantee that it will run a whole lot faster.
Artyoum Artyoum

2014/8/11

#
Thank you very much, I will implement this immediately! Is there any way in which I can obtain what frame rate my world is running at?
danpost danpost

2014/8/11

#
I usually use the speed slider to see how well my scenarios run. I gauge it by when the scenario speed does not seem to increase when continually increasing the slider. If the scenario runs at a faster pace with the speed slider set to right of middle during the most taxing of situations (normally while scrolling is happening), then it should be ok at normal speeds. However, there are multiple 'frames per second' classes/scenarios on the site. In fact, I have a couple myself, FPS Checker and Fps Actor Class.
Artyoum Artyoum

2014/8/11

#
I have just implemented what you have suggested and it has slightly worked. The thing is, I had to reduce map size by at least 1000 pixels to gain maximum efficiency. Thank you for the advice and I will look at those classes.
danpost danpost

2014/8/11

#
The map size should not have needed reducing if you had done what I suggested in my initial post -- create the blue lines and red edges using non-collidable scrollable actors and use a flat gray background for the world that does not need changing. In fact, you should be able to increase the map size immensely by doing so without any lose in efficiency.
Artyoum Artyoum

2014/8/11

#
I believe I have done as you suggested; I have set the paint order in the manner which you have provided in your initial post. I just ran another test in order to see whether it does improve the frame rate and the answer is not really. The map size must be reduced to maximum 2000x1500 for the frame rate to be maintained at acceptable levels. At 2500x2500, even with what you have suggested, the frame rate drops to around 20 frames.
danpost danpost

2014/8/11

#
danpost wrote...
You should make your red edges and blue lines of scrollable actor objects and just keep a flat gray background. Set the paint order so the Car, Player and Lable objects are painted on top of the lines and edges. That way you can dispense with scrolling the background image totally and just reposition the actors (which, for scrolling purposes, does not take any image manipulations). I guarantee that it will run a whole lot faster.
Remove the following two lines from 'scrollUp', 'scrollDown', 'scrollLeft' and 'scrollRight' methods:
1
2
t.drawImage(test, x, y);
setBackground(t);
With the line actors, the background is now a flat gray and does not need to be re-drawn every time the Player object moves.
Artyoum Artyoum

2014/8/12

#
It only works for scrolling right. If you move any other direction, the world does this weird thing and add more objects. I'll upload the game with your current suggestion to show you what I mean. Edit: I found the issue and fixed it. Now it works wonderfully! Thank you for the help!
KalleLarsson KalleLarsson

2014/8/12

#
I recently uploaded my scrolling game, where only the objectsin the World are scrolled, not the background image itself. Please feel free to have a play, then look att the source code. the class ScrollingObjects with the method drawMe() makes scrolling occurs if something moves the "cam" which the player does when he moves into the scroll limits. I have some very big levels (3200x1600) , but it runs smooth (on my computer atleast), since it's just some objects that move
KalleLarsson KalleLarsson

2014/8/18

#
heres the game http://www.greenfoot.org/scenarios/12048
Artyoum Artyoum

2014/8/18

#
Oh, ok, I get it. Simply put, All I may have to do is just remove the methods which scroll the background and just leave the ones which scroll the objects; something around that area, yes?
You need to login to post a reply.