Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有办法做到在windows onload之后再创建舞台? #46

Closed
alexxxcs1 opened this issue Sep 17, 2018 · 3 comments
Closed

有没有办法做到在windows onload之后再创建舞台? #46

alexxxcs1 opened this issue Sep 17, 2018 · 3 comments

Comments

@alexxxcs1
Copy link

现在我是用一个 createstage.js 来创建舞台,再index.js中引入 createstage.js

import {Scene} from 'spritejs';

console.log('in frame window height:' + window.innerHeight);
window.onload = function(){
    console.log('out frame window onloaded height:' + window.innerHeight); 
}
const stage = new Scene('#stage', {
    viewport: [750, 1334-110],  
    resolution: [750,1334-110],
    stickMode: '', 
    stickExtend :true,
}
);
const stageprop = {
    width:stage.resolution[0],
    height:stage.resolution[1],
};

export {stage,stageprop}

这样在场景页面我就能通过stageprop拿到场景的宽高,但是这个宽高其实是设计宽高,手机实际宽高window.innerHeight需要在window.onload里面拿的才是真实的,所以我想问有没有解决方法在window.onload之后再创建舞台?

@alexxxcs1
Copy link
Author

有一个想法是 通过创建对象,这个对象包含init() 和 stage和stageprop,init()之后才创建舞台,然后导出的是这个对象,但是这样做的话我好想所有页面的 stage.layer('xxx')都要改掉...

@akira-cn
Copy link
Contributor

你在window.onload之后再new Scene,或者你先执行了,等window.onload的时候重新设一下scene的viewport

window.onload = function() {
    scene.viewport = [window.innerWidth, window.innerHeight];
    scene.resolution =  [window.innerWidth, window.innerHeight];
}

@alexxxcs1
Copy link
Author

@akira-cn 知道了!谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants