We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way to code an auto scale up and or down feature for different screen sizes on a mobile device? I have tried
function windowResized() { resizeCanvas(windowWidth, windowHeight); }
doesn't seem to work.
I am building in Visual Studio 2015 with Cordova
Answers
https://forum.Processing.org/two/discussions/tagged?Tag=windowresized()
None of these discussions are really getting at what I'm looking for. Thanks though.
Not exactly a trivial question and one that has been asked before (recently)...
I'll see if I can throw a demo together.
Thanks. I look forward to it. Meanwhile I have been manipulating the device controls. I will post a solution if I find one.
Mess around with the integers till it feels right. This seems to do it combined with using displayWidth, displayHeight. Now I just need to figure out how to lock the canvas in landscape.
Create AndroidManifest.xml in res/native/android
@0c00L - here's an initial proof of concept...
Note this currently has a dependency on viewportSize. You'll have to manually paste in the source above the following demo code.
I have some ideas of how this could be wrapped up into a helper script that would make it more useful; for e.g.:
// include viewportSize dependency here... (function(n){ n.getDim=function() { var baseWidth = 600; var baseHeight = 400; var ratioW2H = baseHeight/baseWidth; var windowWidth = viewportSize.getWidth(); var windowHeight = viewportSize.getHeight(); var adjustedHeight = windowWidth * ratioW2H; if(adjustedHeight > windowHeight) { adjustedHeight = windowHeight; windowWidth = windowHeight /ratioW2H; } return { w: windowWidth, h: adjustedHeight} }})(this); // sketch (instance mode) window.P$ = new p5(function (p) { var dim = getDim(); p.setup = function () { p.createCanvas(dim.w, dim.h); }; p.draw = function () { // just to shoe that something is happening p.background('#39d'); // note that position and size are relative to the sketch dimensions p.ellipse(p.width/2, p.height/2, p.width/3,p.width/3); }; p.windowResized = function() { dim = getDim(); p.resizeCanvas(dim.w, dim.h); } }, "sketch01");Updated demo with some additional bells and whistles :)
Thanks @blindfish. I'll study this for fluency but as I started becoming more comfortable with Cordova, I found that it has many ways to mitigate problems such as screen size with ease. Visual Studio 2015 + Cordova = Unlimited power.