Phaser3 Codecademy Levels: creating levels with different platform layouts

Viewed 37

how do I create a platform generating game based on the entries of the 'heights' property of the game scene classes that are extended from Scene?

I found this on codecademy but did not understand...enter image description here

1 Answers

I understand now.

First set this.heights property in the level instances based on the Level class. Since the background image 3(the length of the game) is 2000 and the height is 600, we split the length into 9 sections of 220px and its height into 8 sections of 70px.

enter image description here

Therefore there are 9 numbers in the heights list, each with a value from 0 to 8.

For example: [0, null, 3, 8, 2, 4, 6, 7, 2]. If null, nothing is generated.

Then create platform generating functions based on the heights entries in the original Level class.

enter image description here

enter image description here

Now we can set different heights entries for different level instances and all these levels will have different layout. this way we don't have to place each platform for each level specifically. enter image description here

In the game: enter image description here

The one Codey is standing on might be 5, and the one to the left might be 7.

Please forgive me for any mistakes(I'm a true beginner).

Related