# Convert programs from Phaser 2 to Phaser 3

**URL:** <https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014>\
**Category:** Phaser 3\
**Created:** [April 7, 2019, 5:56pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014 "2019-04-07T17:56:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmarks2061](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dmarks2061/32/1077_2.png) [@dmarks2061](https://phaser.discourse.group/u/dmarks2061)\
**Post date:** [April 7, 2019, 5:56pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/1 "2019-04-07T17:56:08Z")

</div>

I’d like to convert a game I ‘tinkered with,’ written for Phaser 2, to the latest - Phaser 3. It’s based on the Concentration game by Emanuele Feronato in “From null to full.” It didn’t get very far with the Phaser 3 framework!

game.state.add seems like a pretty direct instruction, but Phaser 3 says “Cannot read property ‘add’ of undefined” on line 184, which says “game.state.add(“PreloadAssets”, preloadAssets);”

How is that instruction implemented in Phaser 3? Better yet, is there a document I can reference about the changes between 2 and 3? I have a feeling there will be a lot more Uncaught TypeErrors and such as I go through the process of updating the game.

Yes, I’m a noob. There is a lot of material out there about writing code with Phaser 2. Phaser 3 is still young(ish), and it would be great to convert a lot of that P2 material to current P3 status. Your help will be appreciated! Thanks,

CB\_\_

---

<div class="post-metadata">

**Author:** ![theNeedle](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/theneedle/32/745_2.png) [@theNeedle](https://phaser.discourse.group/u/theNeedle)\
**Post date:** [April 7, 2019, 7:29pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/2 "2019-04-07T19:29:04Z")

</div>

`states` are not there in Phaser 3. Converting v2 game to v3 would be more or less a complete rewrite.

There is no need for converting a game to v3 if your game works fine with v2.

---

<div class="post-metadata">

**Author:** ![dmarks2061](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dmarks2061/32/1077_2.png) [@dmarks2061](https://phaser.discourse.group/u/dmarks2061)\
**Post date:** [April 7, 2019, 9:54pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/3 "2019-04-07T21:54:33Z")

</div>

Thank you for the comments, tN. I have 2 parts to my reply to your reply:

1. **Version Control**. I’ve already wrestled with this one a bit. I have to keep my P2 files with a separate phaser.js file than the P3 files. It would be nice to get them all working off the same version; and,
2. **Learning P3**. I have found a lot of material on developing games with P2. If I could figure out how to convert those ideas to P3, it seems like a phantastic way to learn how to work with P3.  
I might want to take on that kind of project after I get more familiar with Phaser. I just can’t say how long that’ll be!  
Thanks again,  
CB\_\_

---

<div class="post-metadata">

**Author:** ![theNeedle](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/theneedle/32/745_2.png) [@theNeedle](https://phaser.discourse.group/u/theNeedle)\
**Post date:** [April 7, 2019, 10:55pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/4 "2019-04-07T22:55:03Z")

</div>

API of v3 is totally changed. Changing method names will not upgrade any v2 game to use v3.

You can use the game logic/idea described on v2 material to v3 but implementing those ideas in v3 would be almost always different than how it’s implemented in v2.

Take for example

1. `states` in v2 are changed to `scenes`. You can’t run multiple `states` in v2 but you can run multiple `scenes` in v3.
2. `group` in v3 is not same as `group` in v2. You can’t do nesting in v3. Same way you can’t `addChild` to any sprite in v3.

So, how you implement a game in v3 will be different than in v2.  
It’s quite old post but [here](https://phaser.io/phaser3/faq) you can read what Phaser Dev’s say about converting.

[This](https://github.com/samme/phaser3-faq/wiki) will help you to get started with v3.

I didn’t understand the version control part. I guess you can just keep phaser.js files in different directories.

---

<div class="post-metadata">

**Author:** ![dmarks2061](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/dmarks2061/32/1077_2.png) [@dmarks2061](https://phaser.discourse.group/u/dmarks2061)\
**Post date:** [April 7, 2019, 11:59pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/5 "2019-04-07T23:59:12Z")

</div>

Thanks for the pointers; I’ll definitely review them.  
Yah, version control is some form of folder management. Reading your comments, I had another idea, in the webroot folder you could do assets/p2 & assets/p3 and just change the script src to the one you want to use.  
Onward and upward!

CB\_\_

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [March 3, 2023, 5:44pm UTC](https://phaser.discourse.group/t/convert-programs-from-phaser-2-to-phaser-3/2014/6 "2023-03-03T17:44:55Z")

</div>

A post was split to a new topic: [Convert “Shoot 'em Up in an Afternoon” to Phaser 3](https://phaser.discourse.group/t/convert-shoot-em-up-in-an-afternoon-to-phaser-3/12970)
