64 Sprite Collisions
I have a Commodore 64, and am having trouble with collision detection with sprite graphics. I use the following line to check for collisions:
IF (PEEK(53278)ANDX) = X THEN action
This is easy to convert to machine language. In all of my programs, this statement is unreliable. Sometimes it detects a collision between two sprites when they aren't colliding, other times it doesn't detect a collision when they are touching, and other times it works just fine.
I've read in past articles that this problem may be caused by "sparkle" on the 64, and that the solution to the problem is to relocate screen memory. I tried that, and it didn't help.
I've also found that by putting a PRINT PEEK(53279) in my programs, the collision registers work every time. But I don't know how to PRINT a PEEK in machine language.
Eric Rotenberg
First, sparkle can cause spurious collisions with sprites, but you have to relocate the character set, not the screen, to disable the sparkle. Second, be aware of the nature of the collision register. It is set when two sprites collide, and stays set, even after the sprites have moved away from each other.
Also, the register is cleared when you try to read it, so you can't keep doing an LDA or a PEEK to check for different collisions. The first PEEK resets the register. If the sprites are still touching, they will then set the collision register again. When you are checking for a collision, save the results of the first PEEK for later use.