Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,269 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
231,269 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!