It's a 'quirk' in the way that sprite collision works and what happens depends on the colour bitdepth of the screen mode used. (You should always set it).
In your program, you haven't used Set Display Mode, so it defaults to 16bit.
Colour values classed as transparent are not only restricted to the value 0. They depend on the screen bitdepth and are not checked during collision test.
In your program, the sprite's collisions are not being detected due to their colour values. You didn't supply them, so I'm guessing the they are probably primary colours like Red and green.
If they are, then their colour values are probably 255,0,0 and 0,255,0 respectively. With two of the three RGB values being zeros in both sprites, the collision isn't detected. So, you need to change the colour values of at least one sprite.
Run the code snippet of yours (which I altered slightly to correct the layout, account for the missing images/sound and to efficiently demonstrate the problem):
Set Display Mode 800,600,16
Sync On
Sync Rate 0
Hide Mouse
gosub setVariables
gosub makeSprites
Do
Mx=MouseX(): My=MouseY()
gosub moveSprite
Sync
Text 4,4,Str$(SC)
Loop
end
makeSprites:
CLS RGB(255,0,0)
Get Image 1,0,0,33,33,1
rem load image "bitmaps\rect.bmp",1
sprite 1,x,y,1
CLS RGB(1,255,0)
Get Image 2,0,0,33,33,1
rem load image "bitmaps\redend.bmp",2
sprite 2,400,400,2
CLS 0
return:`from makeSprites
setvariables:
x=300
y=240
speed=4
rem load sound "cymbal.wav",999
return:`from setvariables
moveSprite:
`test sound 999
rem play sound 999
if rightkey()=1 and x<600 then inc x,speed
if leftkey()=1 and x>0 then dec x,speed
if downkey()=1 and y<447 then inc y,speed
if upkey()=1 and y>0 then dec y,speed
rem wait 1:`to slow movement
sprite 1,Mx,My,1
rem if sprite hit(1,2)<>0 then play sound 999
SH = sprite hit(1,0)
if SH<>0
Delete Sprite 1
Delete Sprite 2
CLS
Print "Sprite 1 HIT Sprite 2": End
Endif
rem if sprite collision(1,2)<>0 then play sound 999
SC = sprite collision(1,0)
if SC<>0
Delete Sprite 1
Delete Sprite 2
CLS
Print "Sprite 1 COLLIDED With Sprite 2": End
Endif
return:`from moveSprite
Now change the bitdepth on the first line from 16 to 32 and run it again without changing anything.
Now, collision
is detected - and if you look at the code you'll see that all I did was change the red value of one of the images used for the sprites from 0 to 1. (Note: As you have already seen, in 16 bitdepth that alone is not enough).
Normally, this is not a problem as sprite images are rarely a single primary colour and the problem doesn't occur.
TDK_Man