HTML5 Spring Ninja game update: bug fix

My latest tutorial about Spring Ninja has been one of the most popular post of this year, unfortunately most of the feedback received both through comments and private messages was about a bug I really was not able to reproduce, but I think I found a solution anyway.

To check if the ninja is on the top of a pole, in the original script at line 101 I wrote:

if(p.y>=n.y+n.height/2){

p.y is pole vertical position, which has the vertical registration point is on the top of it. n.y is the ninja vertical position, which has the vertical registration point in the middle of it, that’s why we add n.height/2. This ensures us the ninja is on the top of the pole but also can lead to a bug if ninja or pole positions aren’t pixel perfect.

If you change the line with

if(n.body.touching.down){

Which checks for the ninja to touch its bottom side, the bug should be fixed.

Try to change this line and let me know.

  • I tried changing line 101, but I’m still getting the bug.

    It is hard to reproduce, sometimes it will bounce off on the first “clean” landing, but sometimes it will land fine for the first 3 and then bounce off on the 4th.

  • I can’t say that I fully understand the code, but I tried changing the value in line 103 and that seemed to stop the bug for me

    if(Math.abs(border)>51){

    Anything below 50 and I was still seeing it happen. Hoping that you’re still going to release a commented version of this.

    • Emanuele Feronato

      These lines make the ninja fall down if too close to poles edges. Yes, I will comment the code, after showing you how to port it to iPhone :)

  • Pingback: The basics of double jump concept in an endless runner game like Spring Ninja | Emanuele Feronato()