npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

phaser-forcelandscape

v1.0.5

Published

forcelandscape in phaser3

Readme

Phaser3js forceLandscapeScene实现强制横屏效果

原理

根据移动端横竖屏状态来旋转游戏场景(scene) 根据初始化横竖屏状态来旋转角度,进行缩放比例调整

使用方法

1.下载模板phaser3-project-template 2.安装 npm install phaser-forcelandscape

BootScene.js

class BootScene extends ForceLandscapeScene {
  constructor(props) {
	super();
  }
  preload() {
	this.load.image("logo", logoImg);
  }
  renderStartText() {
    const { width, height } = this.scale.baseSize;
    const startText = this.add.text(
      width / 2,
      height / 1.2,
      "PUSH ENTER TO START"
    );
    
    startText.setOrigin(0.5, 0.5);
    startText.alpha = 1;
    startText.setInteractive();
    startText.on("pointerup", function () {
      console.log("start game");
      window.game.scene.sleep("boot");
    });
    this.tweens.add({
      targets: [startText],
      props: {
    	alpha: 0,
      },
      loop: -1,
      duration: 1000,
    });
  }
  create() {
    const { width, height } = this.scale.baseSize;
    this.add.image(width / 2, height / 2.4, "logo");
    this.renderStartText();
  }
}

index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    name="viewport">
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      -webkit-text-size-adjust: none;
      -moz-text-size-adjust: none;
      -ms-text-size-adjust: none;
      text-size-adjust: none
    }

    html,
    body {
      width: 100%;
      height: 100%;
    }

    body {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    canvas {
      margin: 0 auto;
      display: block;
    }
  </style>
</head>

<body>
  <div id="root"></div>
</body>

</html>

index.js

// 判断初始化时候是否屏幕横竖状态
const isLandscape = window.orientation == 90 || window.orientation == -90;
// 移动端高宽比例
let windowRatio =
  document.documentElement.clientWidth / document.documentElement.clientHeight;
windowRatio = isLandscape ? 1 / windowRatio : windowRatio;

// 根据移动端实际高度选择横屏时候合适的canvas宽度
//const width =document.documentElement.clientWidth-100
const width = 650;//相对750
const height = width * windowRatio;

const config = {
  type: Phaser.AUTO,
  physics: {
    default: "arcade",
  },
  scale: {
    model: Phaser.Scale.FIT,
    width,
    height,
    parent: "root",
  },
};
const game = new Phaser.Game(config);
game.scene.add("boot", BootScene, true);

#效果 横竖屏切换保持横屏状态

1.竖屏

2.横屏