Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Hillary Chibuko
Hillary Chibuko

Posted on

Collision detection with javascript

Hello world.....

Todays topic is focused on collision detection, i am a big fan of making 2d games with javscript and i could remember vividly in the past i had to quit some of mu games because of no knowledge on how to handle collisions ....
But luckily i am here to unveil a method that could work.....

I used this for one of my piano tiles game ,basically what it does is render some random tiles and when they are hit they give off a sound...
Seeming interesting huh...

Well for the fun part i handled collisions by simply calling " tiles.getBoundingClientRect().bottom " and i kept monitoring its position which is relative to the window....

So i ran an if statement that checks when the boxBottom cordinates is >= window.innerHeight

So then i would cancel the interval....
Thats it collision detected

For vertical scrolls

Leave a comment if you would like to view the game or source code on github,and you could also suggest me better ways to handle collisions

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

A frontend web developmerBlockchain developerCrypto enthusiast
  • Location
    Lagos,Nigeria
  • Education
    Self taught Developer
  • Joined

More fromHillary Chibuko

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp