You need to define a filter for your character and use it in conjuction with world:move().
Consider the example filter from the github page:
Code: Select all
local playerFilter = function(item, other)
if other.isCoin then return 'cross'
elseif other.isWall then return 'slide'
elseif other.isExit then return 'touch'
elseif other.isSpring then return 'bounce'
end
-- else return nil
end
-- an example on how to use said filter
function movePlayer(player, dt)
local goalX, goalY = player.vx * dt, player.vy * dt
local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
player.x, player.y = actualX, actualY
for i=1,len do
local other = cols[i].other
if other.isCoin then
takeCoin(other)
elseif other.isExit then
changeLevel()
elseif other.isSpring then
highJump()
end
end
end
What this filter does is that the moved object will go right through coins (but still register the collision), slide along the surfaces of walls, stop moving as it touches an exit, and bounces off when hitting a spring. For any other objects, the collisions are ignored.
So in your case, when you want to move your character, it could be something like this:
Code: Select all
local characterFilter = function(item, other)
if other.isButton then return 'cross'
elseif other.isWall then return 'slide'
end
end
-- in character movement code
world:move ( character, destinationX, destinationY, characterFilter ) -- pass the filter to world:move
The important part to remember is that the table you are using for the button needs to contain the field "isButton", and it needs to be a non-false and non-nil value. Like for example:
Code: Select all
local buttonObj = {isButton = true, x = 10, y = 10, w = 20, h = 5}
world:add ( buttonObj, buttonObj.x, buttonObj.y, buttonObj.w, buttonObj.h )
After that you'll just have to figure out how to handle the collision response when the player touches the button.