CHANNELS:

All
k
kaushik posted 2 years ago
b
b1u3ch1p posted 2 years ago

One solution to this would be to add a checkpoint variable to your player class, and set it to false by default.

Create a checkpoint platform wherever you'd like and add your flag object to it. This would be its own object, so name it accordingly so you can reference it later.

If you've been following the videos, use the objectsTouch function and pass in the player and checkpoint flag as the two objects. When this returns true, set player.checkpoint = true.

then at the top of init(), add the following if statement:

if (player.checkpoint) {
player.position.x = checkpointPlatform.position.x
player.position.y = (canvas.height - player.height - checkpointPlatform.image.height)
}
//remaining init code goes under here.

Hopefully this helps!

0

Want to participate?

Create a free Chris Courses account to begin

or
Sign In

Providing the lift to launch your development career

© 2024 Chris Courses. All rights reserved.