We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am using an image in one of my sketches, and I am translating it. This appears to cause it to lag severely. My sketch also has classes, superclasses, and subclasses, as well as PVectors and keyboard interaction, which may contribute to the slowness. I am thinking that simplifying the sketch as much as I can will help it run faster. However, I do not know which parts of the code to simplify and how to simplify it, or if the code size is even part of the problem.
Answers
Where are you loading the image?
Also, it is basically impossible for us to see what might be slowing down your sketch without seeing the code of the sketch.
There is absolutely no correlation between "Code size" (presumably you mean the amount of code written) and performance; and little correlation between code size and 'simplicity' (in terms of maintenance). In fact longer code may perform better and will often be simpler in terms of interpretation.
From the description of your sketch there are many possible factors that could affect performance - maybe you're loading images in draw()? - but without seeing your code we can't know where you should concentrate your efforts...
you should load images in setup and after use image load in draw so program is so fast. also you should use images with necesary size, not big images if you dont need it. you can use requestImage for load several images in time. I have a program that load 200 images in less 3 seconds and after draw is so fast. https://processing.org/reference/requestImage_.html
por example if you are load images from website, program need so time(several seconds) for loadImage, is best save images in data folder or use a requestImage.
Your machine may be too slow to handle the image as well. I just ran into a similar problem like that with multiple windows slowing my machine way down because my graphics card has poor driver support for Windows 7. Once I moved the sketch to a machine that had proper driver support the lagging dissipated.
Here is the some of the code:
PImage bg; void setup() { size(1000, 1000); noStroke(); rectMode(CENTER); bg = requestImage("bleuBoxInABlueWorldBackground.gif"); } void draw() { background(255); pushMatrix(); scale(10); translate(-bb.x/10, -bb.y/10); image(bg, 0, 0); scale(0.1); popMatrix(); }
There are more objects created in setup(), but they are not images (just relatively simple square-like objects).
I am not using many shapes at a time, and I have found that each additional transformation slows the sketch down. However, I think one or two transformations are essential to the sketch. Also, I cannot make the image too large to begin with (before scaling), otherwise the image file is too large to use and causes the sketch to run slowly.
If you post all the code you have and a link to somewhere we can download the image that you have, then maybe we can figure it out.
Thank you for your suggestions. I think I have found the problem, though.
https://sketchtalk.io/discussion/2070/sketch-extremely-slow-performance
That appears to be about Sketch, which is nothing to do with Processing.
https://www.sketchapp.com/