Hi guys.
I have bumped into a problem while making my own collision system. I know how to check for non-transparent pixels, but i have no idea how to check if there are any in a horizontal line. I have tried a for loop, but my character falls through the ground. Here is the function code:
function maskedHLine(x, y, length, image)
for i = 1, length do
local r, g, b, a = imageData:getPixel( x + i, y )
if not a == 0 then
return true
end
end
return false
end
The other one is bad too, but it's merely confusing, not wrong: x == false is better written as not x.
EDIT: also, maskedHLine isn't a very good name, consider renaming it to something like collidesWIthLine or something. It took me a while to figure out when it was supposed to return true. Also, pixel collision is s-l-o-w, know what you're getting yourself into.