KineticJS android stage size

自作多情 提交于 2019-12-23 21:15:14

问题


Definining KineticJS Stage I go like this:

  var stage = new Kinetic.Stage({
    container: 'container',
    width: 320,
    height: 480
  });

So width and height of stage are fixed size. How to stretch it to fit on phone screen if resolution is different?


回答1:


Well, this is really a javascript question. You want to make the size of the stage same as the window size. This worked for me on my android project:

 var stage = new Kinetic.Stage({
      container: 'container',
      width: window.innerWidth,
      height: window.innerHeight
 });

Edit:
Additionally, I recommend you add jQuery as well so you can check for orientation changes, then you can do something like:

window.onresize = function(event) {  //this function will resize your stage to the size of your window
    stage.setWidth(window.innerWidth);
    stage.setHeight(window.innerHeight);
    stage.draw(); //redraw the stage, not sure if really needed, but good to have.
}

or you could do:

window.onresize = function(event) {
    stage.setScale(x,y); //set x, y scale values when the orientation changes
    stage.draw(); //redraw the stage, not sure if really needed, but good to have.
}


来源:https://stackoverflow.com/questions/14989824/kineticjs-android-stage-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!