We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
program lags (Read 1860 times)
program lags
Dec 29th, 2009, 10:19am
 
The only other issue that I've encountered when I'm running my game is that it plays quite slowly. Like it doesn't take long to load, but the image is a bit laggy. I was wondering what could cause that? I've loaded about 13 images total, and have 6 different classes..
Re: program lags
Reply #1 - Dec 29th, 2009, 11:36am
 
What game? If you continue a thread, please link to it.
What do you call a "laggy image"?
What size are your images?
How do you load them?
Re: program lags
Reply #2 - Dec 29th, 2009, 11:52am
 
i didn't actually post all the code to the game that i wrote, but the images aren't high-res, they're pretty small, and I just loaded them using PImage and myImage = loadImage("myImage.png");

And by 'laggy' it just seemed like the whole game was just moving slowly.. it's a scrollscreen, and like when I have the character jump, it seems to be relatively slow. So as of now I'm just messing with the speed variables, such as for the objects and jump speed.
Re: program lags
Reply #3 - Dec 29th, 2009, 11:58am
 
Well, generic advice, because that's a trap lot of newbies fall into: ensure you load the images only once! Eg. put a println() next to the loadImage, and see if they are called several times. If so, avoid that.
As I wrote, some people just load images in draw(), on each frame, which necessarily slows down the program (lot of disk access).
Same for fonts, if any, etc.

How do you make the screen to scroll? Perhaps your method is a bit slow as well. What is the framerate? The graphics mode?
Re: program lags
Reply #4 - Dec 29th, 2009, 12:04pm
 
Ah, okay.. i was actually playing around with it right now, and it seems to be running a lot more smoothly than it originally had been.

I checked, and did only call the images once, I didn't keep calling them for multiple frames.

To make the screen scroll i used
Code:

void draw(){
if (page == 1){
image (titlepage, 0, 0);
backgroundx = 600;
speed = 31.5;
o1.speed = 1.2;
d1.speed = 1.7;
t1.speed = 1.4;
//pf.speed = 1.2;
}else if (page == 1.5){
image (title2, 0, 0);
backgroundx = 600;
}else if (page == 2.5){
backgroundx = backgroundx - 5;
backgroundx = constrain(backgroundx, width-fullbackground2.width, 0);
image (fullbackground2, backgroundx, 0, 3600, 400);
}else if (page == 2){
backgroundx = backgroundx - 5;
backgroundx = constrain(backgroundx, width-fullbackground.width, 0);
image (fullbackground, backgroundx, 0, 3600, 400);

Where backgroundx is the background speed. And o1, d1, and t1 are all classes I called.
Is there a better way to run through the background image?
Re: program lags
Reply #5 - Dec 30th, 2009, 3:15am
 
Well, unless your sketch surface is actually 3600x400, you are doing lot of off-screen drawing just going to waste (ie. cut off).
Actually, this off-screen drawing can be optimized... or not!
It might depend on the graphics mode you chose, among other things.
Looking at image() implementation, I see it is done by texturing a quad shape. Can be fast (in OpenGL?) or quite slow, again depending on underlying implementation, potential hardware acceleration, etc.

In such case, as you do already, only testing alternative solutions and seeing if they are more efficient can help.
For example, you can try using copy() instead of image(), limiting it to the exact size of the sketch.
Page Index Toggle Pages: 1