Skip to content

title: "IsOverlappingWH" description: TRSE built-in method (from IDE help)


IsOverlappingWH

Systems: MOS6502
Parameters: b,b,b,b,b,b


[byte] = IsOverlappingWH( [byte x1], [byte y1], [byte x2], [byte y2], [byte width], [byte height] );

  • [byte x1] - the x position of the first point
  • [byte y1] - the y position of the first point
  • [byte x2] - the x position of the second point
  • [byte y2] - the y position of the second point
  • [byte width] - the distance to check between the two points on the x axis
  • [byte height] - the distance to check between the two points on the y axis

Description

Fast collision test between two points. Returns 1 if [x1/y1] is within [width / height] of [x2/y2], otherwise returns 0.

The distance is tested on the x and y positions and so collision is within a rectangle rather than a straight line distance. Suitable testing for 'hitboxes' between two sprites for example.

Note: This version only accepts byte parameters. To test x position of sprites you must scale the two x positions down to fit between 0 and 255. For example divide by 2 or subtract to bring both values below 256. A future version will support integers.

Assembler Optmisation: If you pass a constant ( eg: 10 or @MyConstant ) or a variable as a parameter, the code produced will be smaller. If pass in a calculation, bear in mind additional code will be created. If you are performing many IsOverapping tests in a loop, do the calculations outside the loop if possible.

Future versions

Example

result := IsOverlappingWH( x,y, enemyx,enemyy, 20, 30 ); // returns 1 if x,y is within 20 width and 30 height of enemyx,enemyy result := IsOverlappingWH( 100,100, x,y, r*2, r ); // returns 1 if x,y is within [r*2] width and r height of 100,100