Share your repls and programming experiences

← Back to all posts
JavaScript Platformer Template!
h
MattDESTROYER

I have finally finished integrating polygon meshes in my JavaScript platformer framework PlatformerJS. You can use it in your HTML projects using:

Please see the template page for documentation, and how to set up a simple platformer. Template Page

Voters
QuickV
BearCoder01
MattDESTROYER
Comments
hotnewtop
QuickV

More stuff: You can walljump on the sides of water (sometimes), and also it seems like on the bouncy level, everything is duplicated.

MattDESTROYER

@QuickV Yep, working on fixing the first, to the second, I think you're on the right track, I think for some reason the every level is invisibly duplicated above and to the left... I have a suspicion it's to do with the way the polygon meshes are moved around when being used for collisions... Basically the idea is that each polygon mesh is designed so it's center is at 0, 0 (x, y), and when the player needs to see if it's colliding, the mesh is moved to the x and y coordinate of the object, the same happens for the player, and if they overlap the player has collided.

MattDESTROYER

@QuickV Update: I think I figured out where the problem was, the PolygonMesh (that was actually kinda surprising, I expected it to be with the player...), I just needed to dramatically increase a value to account for distance, I think it was just a little too low, either way with any luck it's fixed now, I just need to wait for the Repl to find the updated script and test it! :D I originally made the Polygon stuff on KhanAcademy, another site not only for coding; Polygon Collisions Polygon Rotation

MattDESTROYER

@QuickV Update (again xD): Fixed invisible platforms, I think the water wall jumping was a result of the invisible platforms but I could be wrong, either way, I don't think player is able to wall jump on water any more :D

QuickV

Nice! I can't tell if the water level is fixed, because currently there is no water level lol... But the invisible platforms are gone, like you said :D.

Still crashes on the sliding level tho :D...

@MattDESTROYER

QuickV

k :)... Also I know what Khan Academy is :D. @MattDESTROYER

QuickV
MattDESTROYER

@QuickV Water level is broken... :(

QuickV

ah ok ;-; @MattDESTROYER

QuickV

Also it seems there are even more invisible platforms in the bouncy level...

MattDESTROYER

@QuickV I don't know how you figured that out, but thanks :)

QuickV

Well it was pretty easy lol. If you checked the first bouncy platform (at the bottom) it's hitbox was "bigger" than it should have been. Turns out that level was kinda "mirrored" on both sides. @MattDESTROYER

QuickV

Update: It doesn't crash anymore, no matter what I do... Except the invisible block is still there xD.

MattDESTROYER

@QuickV To the first, that's good, although I'm pretty sure it will still crash if a moving PObject, like the one on the level with the sliding PObject, moves into the player's hitbox, it will either crash or walljump., to the second, working on it... I'm still not quite sure what is causing the invisible blocks but hopefully I'll figure it out soon :)

QuickV

It sometimes walljumps, and sometimes just crashes for me lol :) @MattDESTROYER

QuickV

Another thingy: When you're in the water, and you jump from one of the platforms, you kinda teleport up (it thinks it can jump in the water, but I'm pretty sure that's not supposed to be possible).

MattDESTROYER

@QuickV Yep, I knew that, working on fixing it, what's happening is to check if the player is touching water every time the player wants to check if it's colliding, whether it's touching water or not is reset, then the player may 'notice' it's colliding with a solid platform, but it hasn't realised it's in water yet :)

QuickV

ah ok :D @MattDESTROYER

QuickV

Also it crashes randomly 🤔

MattDESTROYER

@QuickV It crashes sometimes when you are running the game in the template section, their is a link that fixes that at the bottom of the template page. It also crashes when an object moves into the player, I am working on fixing that but that should only occur on the demo level with the sliding platform.

QuickV

It crashed once on the first level, and on the sliding one. @MattDESTROYER

MattDESTROYER

@QuickV If it crashes on the first you need to use this link: https://platformer-template.mattdestroyer.repl.co/ (I think it's something to do with the screen sizing when you move the custom console and the code area so that the HTML page takes up the full screen) or it could be that at that time I was making changes to it and that caused the crash but then I later fixed what caused the crash.

MattDESTROYER

@QuickV Because the scripts are on GitHub, it takes a while for the Repl to find the updated version of the scripts which is annoying.

QuickV
QuickV

It doesn't crash anymore, I mean it crashed once @MattDESTROYER

MattDESTROYER

@QuickV That's good :D

QuickV

Is there an invisible block on top of spawn? Or is that a glitch :P... It's probably a glitch, because otherwise someone wouldn't find it in like 5 seconds lol.

MattDESTROYER

@QuickV Yep a glitch, that's an easy fix though, I'll fix it right now, it's to do with how the PText works.

QuickV
MattDESTROYER

@QuickV Alright, apparently it wasn't what I thought it was, I've got school though so I don't have time to fix it now :( sorry, I'll try and fix it tonight

QuickV

it's fine lol! The odds of someone making the game crash is probably like 1/50, so don't worry :P @MattDESTROYER

MattDESTROYER

@QuickV That's definitely in my favour, but I would prefer crashing not to be a problem. :)

QuickV