LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Collision detection without arrays?

Root / Programming Questions / [.]

ahavasandwichCreated:
Hey y'all, I know how to do collision detection by using arrays and player position, but I would like to learn how the built in commands work. I kinda figured out how sprite-spite detection works, but I can't figure out how to do sprite-bg. I've been looking at the code of game that use those commands.....but I'm still not sure how to use them. Thanks for any tips or suggestions.

I haven't tried it myself yet, but the way to do it might be very similar to using arrays - but instead using BGGET to get the BG tile at a given pixel location (which is one of the modes). Alternatively you might be able to use BGCOORD along with SPHITRC. Hope this helps.

For sprite/background collition I use BGGET on the place where I move the sprite. Keep in mind that if you want to collide the lower right corner of the sprite with a background, then you must add the width and height on the argument. Also, if you use BGGET in a tile that contains a letter, then you can compare the same letter with ASC(Letter). For example you could leave the layer 3 like this: AAAAAAA AAAAAAA CCCCCCC Then use BGGET(3,X,Y,1) == ASC("C") to tell if there is collition with the tile "C" at the pixel (X,Y)

Thanks y'all. I try those ideas.