Extensions Test Object

boolean object.testObject ( object object [number layer [, number xoff [, number yoff] ] ] )

Tests if the object is currently overlapping another specified object.

If a layer is specified, the test is limited to instances on that layer.  By default, layer is equal to mmf.ANY_LAYER.  If the xoff or yoff parameters are specified, the test is made as if the object had first been moved by those amounts (but without actually moving the object).

Parameters

object Table representing an object instance
layer Optional.  1-based layer index, or constants mmf.ANY_LAYER, mmf.SAME_LAYER, or mmf.DIFF_LAYER 
xoff Optional.  X coordinate offset to shift object before making the test
yoff Optional.  Y coordinate offset to shift object before making the test

Return Values

boolean true if object is overlapping the specified object, false otherwise

Example

-- Assume we have "Goomba" and "Koopa Shell" objects on the frame
-- Goombas are destroyed if they collide with sliding koopa shells
local ShellClass = mmf.newObjectClass("Koopa Shell")
local GoombaClass = mmf.newObjectClass("Goomba")
 
-- Assume koopa shells have the boolean property "sliding"
for k, shell in pairs(ShellClass.objectList) do
  if (shell.sliding) then
    for j, goomba in pairs(GoombaClass.objectList) do
      if (shell.testObject(goomba)) then
        goomba.Destroy()
      end
    end
  end
end

Copyright 2010 Justin Aquadro