Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Introducing JavaScript Let's Make a Game Doing Things With Functions

Bozena Jablonski
Bozena Jablonski
4,944 Points

My platforms fly off when the player touches them!

By adding the extra coins and platforms I must've messed something up because now the platforms fly off when I touch them. It clearly says 'body.immovable', and I don't think I've edited that part at all.

Any help would be much appreciated, thanks!

https://w.trhou.se/ltvs5irhwc

2 Answers

Steven Parker
Steven Parker
218,654 Points

It looks like you managed to discover something that could be used for some very interesting future games or modifications! :wink:

But you had the right idea about calling "platforms.setAll('body.immovable', true);", you just need to move that down to the end of the "addPlatforms" function so it is called after the platforms are created.

Bozena Jablonski
Bozena Jablonski
4,944 Points

Hi Steven, Thanks! I did think it looked cool, can you think of a way in particular it could be used or harnessed in combination with other effects? Are there similar ones that can be added in a similar way to functions like this?

Steven Parker
Steven Parker
218,654 Points

A few ideas:

  • platforms you have to move to reach a goal or avoid traps
  • objects you have to place to contain a "baddie"
  • a "switch" on the level that would lock or free the platforms

Have you ever seen the original "Commander Keen" games? They do a lot of clever things and most of them can probably be implemented with Phaser.

Ian Johnson
Ian Johnson
2,749 Points

Oh man, this 'error' is so cool!

I know this is an old post, but you can sort of make a new mini game by placing platforms.setAll('body.immovable', true); at different points between the platform code and try get the coins before the platforms slide off/drop/raise up - depending on how you hit them.

Cheers!