So I made a little platformer thingy with only one platform, it moves and jumps just fine, but as soon as i went to make another platform I knew I was doing it wrong.
Instead of trying to explain in detail, just try running the game and you'll see what I mean.
[SOLVED]Platformer help using multiple platforms
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED]Platformer help using multiple platforms
- Attachments
-
- imBadAtMakingPlatformers.love
- (658 Bytes) Downloaded 75 times
Last edited by Vimm on Mon Apr 18, 2016 11:47 pm, edited 1 time in total.
Re: Platformer help using multiple platforms
The first thing i would do is put all platforms into a single table, and loop over them
For example in your love.load() do something like this:
That way you can loop over all platforms;
Example for love.update()
Then you can do the same for love.draw() aswell:
For example in your love.load() do something like this:
Code: Select all
ground = { }
table.insert(ground, {
x = 0,
y = 500,
width = love.window.getWidth(),
height = 32
}
)
table.insert(ground, {
x = 0,
y = 400,
width = 128,
height = 32
}
)
Example for love.update()
Code: Select all
for i, g in ipairs(ground) do
if collision(player.x, player.y, player.width, player.height, g.x, g.y, g.width, g.height) then
--put your collision code here
end
end
end
Then you can do the same for love.draw() aswell:
Code: Select all
for i, g in ipairs(ground) do
love.graphics.rectangle("fill", g.x, g.y, g.width, g.height)
end
Re: Platformer help using multiple platforms
Ohh ok that makes sense, dang, why can't i think of these things on my own XD thanks!unixfreak wrote:The first thing i would do is put all platforms into a single table, and loop over them
For example in your love.load() do something like this:That way you can loop over all platforms;Code: Select all
ground = { } table.insert(ground, { x = 0, y = 500, width = love.window.getWidth(), height = 32 } ) table.insert(ground, { x = 0, y = 400, width = 128, height = 32 } )
Example for love.update()Code: Select all
for i, g in ipairs(ground) do if collision(player.x, player.y, player.width, player.height, g.x, g.y, g.width, g.height) then --put your collision code here end end end
Then you can do the same for love.draw() aswell:Code: Select all
for i, g in ipairs(ground) do love.graphics.rectangle("fill", g.x, g.y, g.width, g.height) end
Who is online
Users browsing this forum: Google [Bot] and 3 guests