Ask coding questions

← Back to all posts
JS if x through another position
vbsoffice

I'm trying to make a snake game and did everything exept walls. A solution I had was to load an image and do a collision. It worked except it only checked for certain position not a x position through another position see the gif bellow:

My Code:

Voters
vbsoffice
Comments
hotnewtop
Coder100

Yeah, it's because the rectangle is centered, just add 8 to the x and y of the snake to account for the width.

Does that make sense?

vbsoffice

@Coder100 Nope. Where do I add it?