So by any chance is there a way is can make a checkpoint an easier way i was think i could do a checkpoint by doing a huge function like init() in you're video but subtract 500 from the platforms and general objerct x position but if there an easier way to make a command i will be glad if you let me know as im wraping my head around how do i make checkpoints as the players x position doesnt change when we move the player but its the platform instead so i came up with this idea and in the animate command i was thinking to do
if(scrollOffset >= 250 && player.position.y>canvas.height) {
Checkpoint()}
else if(scrollOffset <= 250 && player.position.y>canvas.height ){
init()}
else{''}(using an empty string to make the else if work)
so i would be glad if you could tell me how to not make a checkpoint function everytime the player hits a flag (honestly once i make the flags i will add && flag.position.x <= player.position.x to the if commands ) thanks a lot for reading this far and it would really help if you could show me a way to have the charecter near the flag instead of me making a function that subtracts the distance player has travelled from the scrollOffset to the platforms.
in simpler terms how do i not make functions like init() everytime i need the person at the checkpoint because it will be exhausting to do that over and over as right now the player restarts if he falls of the canvas and i dont want him/her to go to the start.
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.xplayer.position.y = (canvas.height - player.height - checkpointPlatform.image.height)}//remaining init code goes under here.Hopefully this helps!
Want to participate?
Create a free Chris Courses account to begin