定义 KineticJS 阶段我是这样的:
var stage = new Kinetic.Stage({
container: 'container',
width: 320,
height: 480
});
所以舞台的宽度和高度是固定的。如果分辨率不同,如何将其拉伸以适合手机屏幕?
定义 KineticJS 阶段我是这样的:
var stage = new Kinetic.Stage({
container: 'container',
width: 320,
height: 480
});
所以舞台的宽度和高度是固定的。如果分辨率不同,如何将其拉伸以适合手机屏幕?
好吧,这确实是一个 javascript 问题。您想让舞台的大小与窗口大小相同。这对我的android项目有用:
var stage = new Kinetic.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});
编辑:
此外,我建议您也添加 jQuery,以便检查方向更改,然后您可以执行以下操作:
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.
}
或者你可以这样做:
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.
}