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.
IndexProgramming Questions & HelpPrograms › Simple animation, performance problem!
Page Index Toggle Pages: 1
Simple animation, performance problem! (Read 488 times)
Simple animation, performance problem!
Dec 17th, 2007, 12:28pm
 
My problem resides in an increasingly falling performance in my program.

I'm building an environment where I use classes for animated objects. From my past experience in java I thought arrays would be the simplest way of handling the objects but it seems that the performance gets alot lower for every single addition to the size of the array... i.e. when adding just one object the performance is falling alot more than previous object.

Do you have any tips on another attack angle at this problem? I've tried playing around with framrates but as expected doesn't matter...

Edit: Changed the title to something more descriptive.
Re: Simple animation, performance problem!
Reply #1 - Dec 17th, 2007, 1:00pm
 
A little piece of code would help us to help you.
Re: Simple animation, performance problem!
Reply #2 - Dec 17th, 2007, 1:41pm
 
eskimoblood wrote on Dec 17th, 2007, 1:00pm:
A little piece of code would help us to help you.


Basically I've got classes that places images at different coordinates depending on input. I think it's the way I load these images that is the flaw, I'm now trying to load them outside of classes and then use them as I initialize the instances of each class instead of loading them inside each instance of each class.

That should let me have just the one loaded image per class instead of one loaded image per instance of each class, right

(I'll see about cutting down the code size, it's fairly large with lots of comments so I'd rather not paste that in here).
Re: Simple animation, performance problem!
Reply #3 - Dec 17th, 2007, 1:55pm
 
Loading the image outside of the class seems to have solved it. =)

Edit: I did find out I can't load the image as part of the main variables (outside of the draw method), so I now have to load them inside the main draw method and use as input variables for the class constructor.

I found that odd, that trying to load the image as public variables didn't work, processing wasn't able to find the path for the image if it's outside the draw method.
Re: Simple animation, performance problem!
Reply #4 - Dec 17th, 2007, 3:47pm
 
These is a way to use only one global instance of an PImage in many classes. Whats slowed your app is loading the image in every draw() methode.

Code:


PImage img

void setup(){
img=loadImage("myImage.gif");
}

void draw(){
MyImageClass m=new MyImageClass(img);
m.drawMe();
}

class MyImageClass{
PImage myImage;

MyImageClass(PImage i){
myImage=i;
}

void drawMe(int x, int y){
image(myImage, x, y);
}
}
Page Index Toggle Pages: 1