That's the probably the route I'm going to do...
Can't have a good platformer without some nice plax scrolling

Code: Select all
local map = sti("maps/01.lua")
map.custom_draw = function(self)
for _, layer in ipairs(self.layers) do
if layer.visible and layer.opacity > 0 then
local r,g,b,a = lg.getColor()
local px, py = layer.properties.speed_x, layer.properties.speed_y -- do your parallax calc here
lg.push()
lg.setColor(r, g, b, a * layer.opacity)
lg.translate(math.floor(px or 0), math.floor(py or 0))
layer:draw()
lg.pop()
end
end
end
function love.draw()
map:custom_draw()
end
Code: Select all
map.plax_draw = function(self, tx, ty)
for _, layer in ipairs(self.layers) do
if layer.visible and layer.opacity > 0 then
local r,g,b,a = love.graphics.getColor()
local px, py=0, 0
if(layer.properties["speed_x"]~=nil)then px=tx*layer.properties["speed_x"] end
if(layer.properties["speed_y"]~=nil) then py=ty*layer.properties["speed_y"] end
if(layer.properties["autoscroll_x"]~=nil)then px=tx+(layer.properties["autoscroll_x"]*layer.scrollx) end
if(layer.properties["autoscroll_y"]~=nil) then py=ty+(layer.properties["autoscroll_y"]*layer.scrolly) end
love.graphics.push()
love.graphics.setColor(r, g, b, layer.opacity)
love.graphics.translate(math.floor(px or 0), math.floor(py or 0))
layer:draw()
love.graphics.pop()
end
end
end
Code: Select all
map:plax_draw(-tx, -ty)
yeah I would like that too considering how short the tutorial ispauljessup wrote: ↑Fri Jan 31, 2020 10:36 pm Sounds good, will do! I was like giving back to the tools I use, when I can
Users browsing this forum: No registered users and 5 guests