The platforms look like this.
Code: Select all
platform = {}
platform.x = 50
platform.y = 400
platform.w = 100
platform.h = 5
table.insert(platforms, platform)
Code: Select all
love.graphics.draw(natplat1, x, y)
Code: Select all
platform = {}
platform.x = 50
platform.y = 400
platform.w = 100
platform.h = 5
table.insert(platforms, platform)
Code: Select all
love.graphics.draw(natplat1, x, y)
Code: Select all
function newplatform(x, y, w, h)
return {x = x, y = y, width = w, height = h}
end
Code: Select all
table.insert(platforms, newplatform(x, y, w, h))
Code: Select all
function drawplatform(platform)
local x, y, w, h = unpack(platform)
love.graphics.rectangle("fill", x, y, w, h)
end
Code: Select all
drawplatform(platforms[i])
Code: Select all
platform = {}
function newplatform(x, y, w, h)
return {x = x, y = y, width = w, height = h}
end
function drawplatform(platform)
local x, y, w, h = unpack(platform)
love.graphics.rectangle("fill", x, y, w, h)
end
function love.load()
end
function love.update(dt)
table.insert(platforms, newplatform(x, y, w, h))
end
function love.draw()
drawplatform(platforms[i])
end
Oh, okay then.GungnirDev wrote:I am not quite sure where you are meaning for me to plug these in. I've rearranged the code a few times but I keep receiving 'syntax' or 'nil' errors. I've not done many shortcuts in LOVE before.
To better help you understand my predicament, I am already able to create rectangular platforms. However, I have platform-images with irregular shapes, and I want to use these as platforms. So, I want to create a platform for each horizontal surface of this platform, and also post the image, and create this as a single platform (let's say, called, natplat2).Code: Select all
platform = {} function newplatform(x, y, w, h) return {x = x, y = y, width = w, height = h} end function drawplatform(platform) local x, y, w, h = unpack(platform) love.graphics.rectangle("fill", x, y, w, h) end function love.load() end function love.update(dt) table.insert(platforms, newplatform(x, y, w, h)) end function love.draw() drawplatform(platforms[i]) end
Then, by typing natplat2(x, y) I should be able to place this platform anywhere I choose. Does that make more sense?
Code: Select all
local imgdata = love.image.newImageData(platform mask image)
local platsToDo = {}
for x = 0, imgdata:getWidth()-1 do
for y = 0, imgdata:getHeight()-1 do
local r, g, b, a = imgdata:getPixel(x, y)
if a == 255 then --If opaque, and not transparent
if platsToDo[r.."-"..g.."-"..b] then
platsToDo[r.."-"..g.."-"..b][2] = {x+1, y+1}
else
platsToDo[r.."-"..g.."-"..b] = {}
platsToDo[r.."-"..g.."-"..b][1] = {x+1, y+1}
end
end
end
end
for i, v in pairs(platsToDo) do
if v[1] and v[2] then --make a rectangle
table.insert(platforms, platform:new(v[1][1], v[1][2], v[2][1]-v[1][1], v[2][2]-v[1][2])
end
end
Code: Select all
table.insert(platforms, platform:new(v[1][1], v[1][2], v[2][1]-v[1][1], v[2][2]-v[1][2])
No, this is general code. I mean, it works in most versions of LÖVE, including 0.8.0 and 0.9.0.GungnirDev wrote:Ok, that's good, but now I have problems. I tacked on a parenthesis after
since it was giving me an error. Now I get a different error: 'attempt to call method 'new' (a nil value).' I think it might be a problem with your solution being dated for love 8.0? Maybe there is a different term used in 9.0.Code: Select all
table.insert(platforms, platform:new(v[1][1], v[1][2], v[2][1]-v[1][1], v[2][2]-v[1][2])
Users browsing this forum: Amazon [Bot], Bing [Bot] and 6 guests