跳转至

【注译说明】

注、译自Phaser 3 FAQ/常识答问,作者为Jdotr。

Frequently Asked Questions#

(that we have answers to) // 常见问题 // (我们有答案的)

Also note that @samme maintains another FAQ that you can check out! // 也请关注samme维护的另一个常识答问。

What is Phaser 4? Didn't Phaser 3 just come out?#

//Phaser 4是什么?3不是刚出来吗?

_Last Updated: 2019-10-23

Phaser 4 is like an evolution of Phaser 3. Keep the best parts and improve the rest. Phaser 4 will be written in TypeScript and be more modular and tree-shakeable. The development has just started, but the plan is for you to be able to either use a Phaser 3-like API, or the new style of importing and using just what you need. You can read more about it in Rich's patreon post // 4是3的进化版,继承好的部分,改进不足的部分,用typescript写成,会更加模块化。

I'm new to Phaser, what should I do?#

// 我是新学Phaser,该怎么做?

Last Updated: 2018-05-17

The key to learning game dev / Phaser is to just build stuff, it doesn't need to be good or even complete. The more you program the more you know and the easier it is to make what you imagine real. // 学游戏开发/Phaser的关键是_只管多多地做东西_……

That said, if having a list of things that help you get started is useful we've compiled a bunch of introductory guides. They're ordered based on how much you're expected to already know and we're always happy to take suggestions about new stuff that should be added to the list. // 我们已经编制了一串入门指导的清单……按学习次序排列……

  1. Getting Started—This introduces you to the basics of how to run your game and gives provides a super simple game you can create.
  2. Making your first game—Once you're comfortable with running a server and editing code work through this. It introduces some basic systems involved in a Phaser game.
  3. How to create a game—This is a similar slice of information as Making your first game but covers enough different information that it's worth reading through as well.
  4. How to structure your code—This isn't about how to program exactly but talks a little bit about how to organize your project so that it's easy to keep building on what you've got. Optional reading but I feel it's an important bit of information.
  5. Ask for help—Get involved in the community! It's dangerous to go alone, take a friend, and don't be afraid to ask for help.
  6. How scenes work—Goes into more detail about how scenes can work and can fit into your game.

Disclaimer: the author of this list wrote the structure and scenes posts

The phaser examples page is a rich source of code samples demonstrating various aspects of the Phaser framework. // Phaser官网实例。

The phaser API docs is an ever-improving source of information and great for self-directed exploration. // PhaserAPI文档。

If you'd like to help this list grow we'd like to add:

  • some guides about javascript basics etc
  • some simple sample projects with documentation

Where is the documentation and/or examples?#

// 哪里有文档和实例?

Last Updated: 2018-09-16

The phaser examples page is a rich source of code samples demonstrating various aspects of the Phaser framework.

The phaser API docs is an ever-improving source of information and great for self-directed exploration.

How do I get started with multiplayer games?#

// 做多人游戏从哪儿下手?

Work in progress, last updated: 2018-06-20

Right now this is just a collection of links that potentially may be useful:

  • (A great free course from Udacity / Google) https://eu.udacity.com/course/html5-game-development--cs255
  • http://buildnewgames.com/real-time-multiplayer/
  • http://www.gabrielgambetta.com/client-side-prediction-server-reconciliation.html
  • (for phaser v2 but the theory is there) http://www.dynetisgames.com/2017/03/06/how-to-make-a-multiplayer-online-game-with-phaser-socket-io-and-node-js/
  • (written in Haxe, but the theory is there) http://antriel.com/post/online-platformer-1/
  • (non-code theory) https://gafferongames.com/post/what_every_programmer_needs_to_know_about_game_networking/
  • (probably not where you want to start but quality info) https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

How do I scale a Phaser 3 game? Is there a ScaleManager in v3?#

// 我怎么适配Phaser 3游戏。Phaser3有ScaleManager(Phaser2的类,屏幕适配用)吗?

Last Updated: 2019-3-29

With the release of 3.16, Phaser now comes with a ScaleManager built in! Examples on it can be found here. //3.16后有

If you're not on 3.16 or above you'll have to roll your own solution. Heres some examples // 3.16以前的解决方法

  • Example page from DannyT includes functional examples built using some of the principles discussed in the following links
  • this gist from Str1ngS bundles some scaling functionality into a class and demonstrates how to hook it into your game; the orientation and content references are HTML elements in your page that you cane use to implement "wrong orientation" overlays as described in this post
  • this thread includes a (Haxe) code sample from community member Antriel
  • a codepen sample linked from Samme includes another promising solution
  • Scaling without framework support Emanuele works through the principles of scaling your game regardless of framework support
  • James Pierce posted the code he uses for scaling a game across devices

Tell me the story of Phaser v3 and Typescript#

// 跟我说说Phaser3和Typescript。

Last Updated: 2019-10-08

Typescript defs for Phaser have been available for a long time now. They are considered stable enough, and have been included in the types folder of the Phaser repository since Phaser 3.17. If you install Phaser with npm, that means you already have them downloaded. Before 3.17 they were available at photonstorm/phaser3-docs. If you are stuck on an old version, that file is the one you want to use, just make sure to use the one corresponding yo your version. Previously, phaser#3224 was the official tracking ticket for typescript support in Phaser.

Is there a guide to porting my v2/CE project to v3?#

// Phaser2/CE迁移到3,有指导吗?

Last Updated: 2018-03-14

Not yet. There is a partial guide in Newsletter issue 116 in the section named Moving from Phaser 2 to Phaser 3 (Part 1). Part 2 is in issue 118.

The API is similar enough that you will feel comfortable once you've figured out where things live but there is no mechanical solution to making a CE project run in v3. In that way it's definitely possible to make the jump for an existing project.

That said, enough essential things are different (no ScaleManager yet, Scene works differently than State, etc.) that it takes a little thinking. The work to describe how all the old CE concepts map into v3 is planned but currently incomplete.

Should I use Phaser CE or v3?#

// 我该用PhaserCE还是Phaser3?

Last Updated: 2018-02-10 / 2018-10-28

tl;dr: One of our members made a video talking about deciding whether or not to use v3: go watch it (thanks Wild)! For production stuff, Phaser CE is still a good choice, but if you're learning Phaser and/or feeling adventurous then v3 is a pretty good bet, and it's becoming better every day.

That video was recorded Feb 10th. Since then we (the community at large) have leveled up several times about how well we understand and how much we've experimented with v3. Tutorials are beginning to emerge and several patch releases have appeared fixing bugs and adding previosly missing features. Broadly speaking getting into V3 is much easier than it was but still seeing quite a bit of development. If you're adventurous and willing to dig v3 is a good place to be. The API is cleaner than CE and it's definitely the future of Phaser so learning it to start with is probably a good move.

If you need something exceptionally stable and battle worn that you can take into production right now then you probably still want to stick with CE for the time being. By the numbers most deployed Phaser games are CE which means more time has been spent understanding it's edge cases. You're not going to see as many bugs or API changes than working off V3 but you're also not going to see any improvements.

My game behaves inconsistent/stops running while in the background#

// 我的游戏后台运行有问题/停止

Last Updated: 2018-10-26

Modern browsers place several restrictions on websites that run in the background. This usually means background tabs, but can also influence windows that are unfocused or partly hidden by another window. When in the background, requestAnimationFrame is not triggered, and it may be throttled when the website is unfocused. This means that Phaser's update loop won't run. Additionally, timers in background tabs may run less frequently than they normally would. Chrome only executes timers once per second, while Firefox has similar policies. The timers may be throttled even more in some cases. Playing audio or using websockets are usually an exception to this additional throttling.

More details: - Background tabs in chrome - MDN page about background page policies

How do I post code?#

// 我怎么粘贴代码?

Last Updated: 2018-11-03

If you have a small bit of code (less than about 20-30 lines) to share the easiest approach is using the formatting support built into Discord. This means using ```javascript on a line by itself then entering your code:

code format sample

If you have a longer or multi-file segment of code creating a new gist or codepen is better.

评论