Hi,
How can I reliably provide width
and height
to the constructor while creating an object instance.
I am constructing a “device object” from a class which is automatically loaded before setup() is executed. In the device constructor I am using width and height as a reference to the device about the screen size. Since setup() is not yet processed at this point, width and height read as 100.0. So this doesn’t work.
I can’t use globals in setup. What would be a normal solution for this problem.
Here some example code:
In my root file:
void setup() {
size(1600, 1200);
}
Device myDevice = new Device(width, height);
in my device class (different tab/file)
class Device{
int objWidth;
int objHeight;
int screenWidth;
int screenHeight;
Device(int sW, int sH){
objWidth = 300;
objHeight = 60;
screenWidth = sW;
screenHeight = sH;
position.y = screenHeight / 2;
position.x = 0;
}
}
If not clear enough, please let ne know
Cheers,
Stowoda