map.TestMoveX

Apply horizontal movement to an object's position and test if it will collide.

Syntax

map.TestMoveX(x, y, w, h, newx)

Parameters

  • x - Horizontal position of the rectangle.
  • y - Vertical position of the rectangle.
  • w - Width of the rectangle.
  • h - Height of the rectangle.
  • newx - New horizontal position of the rectangle.

Returns

A +/- integer offset that when added to `newx` will remove the object under test from collision. A zero value indicates no collision has occurred.

About

Knowing whether a collision has happened is often not enough, as you might need to keep the player inside a known region. map.TestMoveX and map.TestMoveY allow you to test if a potential horizontal or vertical movement will cause a collision.

If so, it will return a correction factor needed to remove the object from the collision. In this way, you can build walls that players can slide along and won’t escape from.