Extensions Test Rectangle

boolean mmf.frame.testRect ( number x, number y, number w, number h [, number layer] )

Test a rectangular region of the frame's collision mask for a backdrop obstacle.  The test can optionally be limited to a layer.

Parameters

x X coordinate on frame
y Y coordinate on frame
w Width of rectangular region
h Height of rectangular region
layer Optional.  1-based layer index, or constant mmf.ANY_LAYER

Return Values

boolean true if there's an obstacle within the rectangular region, false otherwise

Example

-- Assume we have an object "goomba"
-- Turn around if he hit a backdrop while moving right
local x = goomba.xRight
local y = goomba.yTop
local w = 2
local h = goomba.yBottom - goomba.yTop
 
if (mmf.frame.testRect(x, y, w, h)) then
  goomba.x = goomba.x - 1
  goomba.direction = mmf.DIR_W
end

Copyright 2010 Justin Aquadro