All the "vector" functions exist so that you can perform collision detection BEFORE moving the sprite. For instance, let's say you're walking forward and you hit a wall. Usually, you stop characters from hitting the wall by seeing if the place you're going to be in is IN the wall, then not updating the position if so.
Let's say you want to use sprite collision detection to detect the hit wall. You'd want to use SPOFS to move the character sprite into the new position and use SPHITSP* or SPHITRC** to detect the hit, but unfortunately, the behavior of SPOFS isn't consistent when used with SPHITSP and SPHITRC, so this isn't reliable.
With SPCOLVEC, you can say "this is how fast the sprite is currently travelling per frame." Now, SmileBASIC will detect hits wherever the sprite WILL BE on this frame rather than where it currently is. So, hitting a wall becomes as easy as setting the player velocity with SPCOLVEC, then performing the regular sprite hit detection.
If all that is too much, think of SPCOLVEC as telling SmileBASIC to look into the future for hit detection rather than the present.
* = sprite hitting sprite detection
** = sprite hitting rectangle detection
SPCOL
Before using any of these commands, you must enable collision detection using SPCOL.SPCOL IDIf you want collision detection to work on SPSCALEd sprites, you must do
SPCOL ID,TRUE 'BEFORE using SPSCALEYou can also set a collision mask:
SPCOL ID,TRUE,MaskSprites will only collide if their masks have some of the same bits set. &B100 will collide with &B111 but not &B001.
SPHITSP
SPHITSP checks for collision between sprites. Check collision between one sprite and any other sprite:CollisionID = SPHITSP( ID )Check collision between two specific sprites:
CollisionID = SPHITSP( ID1, ID2 )Check collision between one sprite and a range of other sprites:
CollisionID = SPHITSP( ID, LowID, HighID )
SPHITRC
SPHITRC checks if a sprite is touching a rectangular area.CollisionID=SPHITRC(X,Y,Width,Height) CollisionID=SPHITRC(ID ,X,Y,Width,Height) CollisionID=SPHITRC(LowID,HighID ,X,Y,Width,Height)You can also specify the mask and SPCOLVEC information for the rectangle:
CollisionID=SPHITRC([...,] X,Y,Width,Height,Mask[,VX,VY])
SPHITINFO
You can use SPHITINFO to get more information about the last collision.SPHITINFO OUT Time[,X1,Y1[,VX1,VY1],X2,Y2[,VX2,VY2]]Time is a real number between 0 and 1 and I have no idea what it does After calling SPHITSP/RC normally, you can call SPHITSP() or SPHITRC() again with no arguments. This will give you information about other collisions (if there are any) or just return -1.