# 自动横屏与横屏游戏（JS）

711501594

LayaAir引擎如何设置自动横屏

 12345678910111213141516171819202122232425262728293031323334 `(``function``()``{``    ``var` `Stage = Laya.Stage;``    ``var` `Text  = Laya.Text;`` ` `    ``(``function``()``    ``{``        ``//初始化舞台``        ``Laya.init(500, 300);``        ``//让舞台处于屏幕的垂直居中``        ``Laya.stage.alignV = Stage.ALIGN_MIDDLE;``        ``//让舞台处于屏幕的水平居中``        ``Laya.stage.alignH = Stage.ALIGN_CENTER;``        ``//保持原始高宽比的情况下，将舞台铺满屏幕，超出比例的部分会有黑边``        ``Laya.stage.scaleMode = Stage.SCALE_SHOWALL;``        ``//`自动横屏，舞台的水平方向与屏幕的最短边保持垂直。`        ``Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;``        ``//设置舞台背景色``        ``Laya.stage.bgColor = ``"#232628"``;``        ``showText();``    ``})();`` ` `    ``function` `showText()``    ``{``        ``var` `text = ``new` `Text();``        ``text.text = ``"成功实现自动横屏！"``;``        ``text.color = ``"gray"``;``        ``text.fontSize = 50;``        ``text.x = Laya.stage.width - text.width >> 1;``        ``text.y = Laya.stage.height - text.height >> 1;` `        ``Laya.stage.addChild(text);``     ``}``})();`
{"ft_lang_label":"__label__zh","ft_lang_prob":0.91670614,"math_prob":0.7040393,"size":1878,"snap":"2020-45-2020-50","text_gpt3_token_len":1585,"char_repetition_ratio":0.10565635,"word_repetition_ratio":0.0,"special_character_ratio":0.23482428,"punctuation_ratio":0.20866142,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9721186,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-04T03:02:50Z\",\"WARC-Record-ID\":\"<urn:uuid:cb5510ed-3b77-4bc2-8a0c-5534cc943be0>\",\"Content-Length\":\"67210\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cb3a3de9-dc48-4156-9b65-8e30848cd1d9>\",\"WARC-Concurrent-To\":\"<urn:uuid:fb81b822-918f-430e-91ef-22da919bcebd>\",\"WARC-IP-Address\":\"220.249.244.119\",\"WARC-Target-URI\":\"https://gameinstitute.qq.com/community/detail/112010\",\"WARC-Payload-Digest\":\"sha1:5TJ6O3X2SIM4RKBTAQHRSGDKW66JNV4A\",\"WARC-Block-Digest\":\"sha1:IQP6VVV3AF2PGACYQIKWRTR2WQBXBBSN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141733120.84_warc_CC-MAIN-20201204010410-20201204040410-00388.warc.gz\"}"}