Boolsheet wrote:Your function is trying to get a pixel outside of the image. This throws an exception and love quits.
ImageData in love goes from 0, 0 to width-1, height-1. To stay inside the image you could change
function readImg(fileName)
local iD = love.image.newImageData(fileName)
local t = {img = love.graphics.newImage(fileName),map = {}}
local width = t.img:getWidth()
local height = t.img:getHeight()
local temp
for w = 1,width,-1 do
t.map[w] = {}
for h = 1,height,-1 do
temp = {iD:getPixel(w,h)}
if temp[4] > 0 then
t.map[w][h] = true
else
t.map[w][h] = false
end
end
end
return t
end
Last edited by Buddy4point0 on Sun Jan 16, 2011 10:35 am, edited 1 time in total.
Buddy4point0 wrote:I read it, and I don't agree with you or the creator of the article at all.
To be more specific, I have to make a pixel perfect collision system for what I'm working on right now. So I figure I might as well make it re-useable.
But that's exactly what the writer of the article was saying: you don't create a collision system out of the blue, but you make it with a specific use (i.e. your game) in mind. Making it reusable is the second step, not the first.
Buddy4point0 wrote:Ok, I looked on the Lua 5.1 Reference Manualand I don't see anything about lists.
What are they and how would I use the information in it? If you don't feel like answering though, it's fine because I got it figured out thanks to Thelinx.
Lists are very weak in Lua, they disappear in a puff of smoke, for example:
function afunc(...)
print(...) -- ... is a list here. You can pass it to another function.
print((...)) -- only the first element in the list is passed
-- lists can be put into tables like this:
atable = {...}
return 1, 2, 3 -- this function returns a list
end
Buddy4point0 wrote:Ok, I looked on the Lua 5.1 Reference Manualand I don't see anything about lists.
What are they and how would I use the information in it? If you don't feel like answering though, it's fine because I got it figured out thanks to Thelinx.
Lists are very weak in Lua, they disappear in a puff of smoke, for example:
function afunc(...)
print(...) -- ... is a list here. You can pass it to another function.
print((...)) -- only the first element in the list is passed
-- lists can be put into tables like this:
atable = {...}
return 1, 2, 3 -- this function returns a list
end