08-17-2024, 06:51 PM
I depends on the situation I suppose. Take this rectangular collision code for example:
IF R1.right >= R2.left THEN ' check for overlapping coordinates
IF R1.left <= R2.right THEN
IF R1.bottom >= R2.top THEN
IF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
END IF
END IF
END IF
ELSEIF would not work in this case. Also, at any point one of the IF statements becomes FALSE the remaining IF statements are skipped, speeding up the process.
I'm with Steve on this as well. For a situation where many ELSEIFs are required I would rather use SELECT CASE because of its clean style and easy readability.
IF R1.right >= R2.left THEN ' check for overlapping coordinates
IF R1.left <= R2.right THEN
IF R1.bottom >= R2.top THEN
IF R1.top <= R2.bottom THEN ' all checks passed, must be a collision
RectCollide% = -1 ' return that a collision was detected (TRUE)
END IF
END IF
END IF
END IF
ELSEIF would not work in this case. Also, at any point one of the IF statements becomes FALSE the remaining IF statements are skipped, speeding up the process.
I'm with Steve on this as well. For a situation where many ELSEIFs are required I would rather use SELECT CASE because of its clean style and easy readability.