We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi Everyone,
I coded a game for the screen size 600x600. Now, somebody complained that it is too small, so I would like to scale it up 1.5 times (to 900x900).
I have some variables defined in the very beginning, then some in the void setup(){..}
, and so as a first option I tried to do the following:
void setup(){
size(900,900); // changing from size(600,600);
}
void draw(){
scale(1.5); // changing from scale(1);
}
The buttons do not work... seems like the mouseX
and mouseY
positions are as they were in the original 600x600 frame, even though the visuals are scaled up.
I also thought that maybe automatically scaling a Processing.js sketch to fit the browser window could solve this issue.
As a second option, I thought that including this code in jQuery could work:
function doResize()
{
var setupHeight = Math.max($(document).height(), $(window).height());
$('#GAME').width($(window).width());
$('#GAME').height(setupHeight);
size($(window).width(), setupHeight);
}
$(window).resize(doResize);
Then in void setup()
, I replaced size(800, 800)
with doResize()
.
Still I could not make it.
I would appreciate any suggestions or examples related to scaling up the whole sketch at once. Thanks in advance!
(ps. the code is too long to paste it here.)
Answers
"seems like the mouseX and mouseY positions are as they were in the original 600x600 frame, even though the visuals are scaled up"
Actually, no, but when you scale up, the buttons are farther (moved down and to the right) and bigger, so the test for rectangle hit must compensate this...
@PhiLho it seems like that hitting in the "previous" positions, highlights the new shifted buttons... If i click somewhere up and to the left, the button to the right and down gets highlighted.
.
for scale 1.5
try all "mouseX and MouseY, mouseX/1.5 and mouseY/1.5
For clarification... the mouse coordinates (
mouseX
andmouseY
) aren't adjusted byscale()
. This function only affects things that are drawn. You have to scale the mouse coordinates yourself.Yes, either you scale down mouseX/Y as shown, to move back these coordinates into the unscaled button position / size, or you multiply the values you test against.
this example work correctly in 19201080 (draw) 1024820 android Acer 800 * 480 android samsung SII
void setup() { //size (1000,700); size (displayWidth, displayHeight); } void draw () { scale (1.5);
fill (255, 0, 0); if (mouseX/1.5 >250 && mouseX/1.5< 350 && mouseY/1.5 > 250 && mouseY/1.5 < 350) { fill (255, 0, 255); } ellipse (300, 300, 40, 40 ); }
with "translate", example
Thank you @PhiLho, @calsign, @camperos for your excellent suggestions, and clarifications!
I followed the first example by @camperos to modify my game code and the buttons started working again:
I also had to change some
int
variables (the ones depending on mouseX and mouseY) intofloat
ones. Then in one instance I had to convert the division toint
:After the buttons were working, I then faced another issue: some graphics were also displaced due to some other system variables, specifically:
height
andwidth
that were used to draw graphics.I replaced those variables with the fixed variables
sH=600
andsW=600
. I believe, however, the same scaling down method (height/sclFctr
andwidth/sclFctr
) could have worked in this case as well.In addition, the following part of the code did not work for my needs:
It looked great, but was way too large and irregular to accommodate the graphics that were drawn to fit a square frame. So stayed with initial
size(900, 900);
Thanks again for your help!
UPDATE: the sketch does not work in JavaScript... at some state of the game, the graphics start growing with the frame rate and explode crashing the browser. It appears as it was scaling the drawing infinitely.