Jump to content

boxcollision examples

Karl G

Recommended Posts

Are there any sample programs using boxcollision? I'm not having luck with it despite the fact that I think I have the parameters right, and I'm not dealing with anything offscreen.


Edit: Nevermind; found in samples. I was spelling collision wrong in my search.  ?

  • Like 1
Link to comment
Share on other sites

    if boxcollision(TaxiX, TaxiY, 8, 5, 0, 64, 72, 1) then gosub StartCrash

Here's my boxcollision line. I am checking if my taxi sprite with a width of 8 and height of 5 collides with a strip of the background starting at x=0 and y=64 which is 72 in width and 1 pixel tall.


I guess I was assuming here that I could use boxcollision to detect collisions with the background, and not just with other actual sprites. Is this the case, or do I need to write my own function for these kinds of collisions?

Link to comment
Share on other sites

You could use box collision with anything, but checking if two boxes overlap is a bit expensive on the 6502. If you do a few of them it's not too bad, but it quickly adds up.


For anything tile-based, it's more efficient to check points on the sprite to see if they've moved over top of a particular tile index (or range of tile indexes). If you organize your tiles, you can easily have a set on non-harmful tiles, harmful tiles, goal or trigger tiles, etc.



Link to comment
Share on other sites

Ok, let me walk one point back a little bit. Collision with very large widths will cause byte overflows, which will mess up the collision.


Mostly unrelated to the above, I also see a bug when the first object x coordinate is less than it's width, if you're not using collisionwrap. For the next release I believe I'm going to make collisionwrap on by default. In the meantime I'd recommend using collisionwrap in your code.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...