How to use Tiled (or not) with a platformer

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

How to use Tiled (or not) with a platformer

Post by hasen »

I want to use the the Stalker X camera library with a platform game and I was planning to use Tiled to make the levels, however, I was informed in another thread that the STI library doesn't work well with camera libraries...so what would be the best way to implement Tiled with a Love2d platformer? Maybe I could do without Tiled but I'm not sure what I would do instead to make the levels?
User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: How to use Tiled (or not) with a platformer

Post by jojomickymack »

You should definitely stick with Tiled and STI, it's going to simplify collision detection, level building, and art management massively. The reason STI isn't going to work with camera libraries is because in order to be as stable as possible, it needs to do it's own translation and scaling when it draws the layers.

The tutorial is still good for covering how to get up and running with it.

http://lua.space/gamedev/using-tiled-maps-in-love

Just keep in mind that the last line of the example there isn't correct, since translating and scaling the map is done in the call to draw the map.

Map:draw (tx, ty, sx, sy)
Draw every Layer
Parameters:

tx Translate on X
ty Translate on Y
sx Scale on X
sy Scale on Y

That's the key to scrolling the map around, if you really want some of those features stalkerX provides, like shaking the viewport or allowing leading room in the direction the player is moving in, you can easily implement them with the translation/scaling parameters. It's certainly easiest to just translate based on the player's position like it shows in the example.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to use Tiled (or not) with a platformer

Post by hasen »

jojomickymack wrote: Mon Jan 22, 2018 2:42 am You should definitely stick with Tiled and STI, it's going to simplify collision detection, level building, and art management massively. The reason STI isn't going to work with camera libraries is because in order to be as stable as possible, it needs to do it's own translation and scaling when it draws the layers.
This is all quite confusing. The Stalker X camera is designed for use with platformers, it has a mode for that. Also it has features built in like camera shake all ready to use. Although I was advised not to use STI with a camera module but conversely I'm advised also to make sure I use STI and not use a camera.

Not sure what's the best approach for a platform shooter..aside from programming all or some of the modules myself of course but since I've never used Love2d or even programmed a game before that feels a bit daunting.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How to use Tiled (or not) with a platformer

Post by erasio »

I said that STI doesn't play nice with camera libraries because it resets them before drawing the map.

And that you must provide the camera translation (without rotation which you mustn't use without modifying STI) to the sti map if you want to use it.
So you can use a camera. But you are more limited and need to make sure to not use the player location but the camera location as parameter for STI maps. Since that's what you expect to draw.
Admittedly I confused sti with another library which didn't have scaling either. So that's my bad. Scaling works. Only rotation is off limits.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to use Tiled (or not) with a platformer

Post by hasen »

erasio wrote: Mon Jan 22, 2018 8:23 am Admittedly I confused sti with another library which didn't have scaling either. So that's my bad. Scaling works. Only rotation is off limits.
Ok I see. So it can work but not really recommended.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: How to use Tiled (or not) with a platformer

Post by erasio »

It's not so much a recommendation to not use it but rather a limitation to be aware of.

I mean do you need to rotate your screen? Is that important to you? (not characters or objects in your world. You can rotate those just fine)

If it is, then yeah. I would recommend looking into how easy it is to fix that in sti by yourself or look for alternatives.

Realistically. A lot of games don't need camera rotation though.

If this limitation is OK for you it'll just be a bit of extra work to apply the same transformation to both the map and the camera (probably by accessing your camera and reading out it's location and passing that on to the sti map).
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to use Tiled (or not) with a platformer

Post by hasen »

erasio wrote: Mon Jan 22, 2018 5:33 pm It's not so much a recommendation to not use it but rather a limitation to be aware of.

I mean do you need to rotate your screen? Is that important to you? (not characters or objects in your world. You can rotate those just fine)

If it is, then yeah. I would recommend looking into how easy it is to fix that in sti by yourself or look for alternatives.

Realistically. A lot of games don't need camera rotation though.

If this limitation is OK for you it'll just be a bit of extra work to apply the same transformation to both the map and the camera (probably by accessing your camera and reading out it's location and passing that on to the sti map).
No I shouldn't think I'll need screen rotation....screen shake would be good though. I couldn't get STI to work with the Stalker camera at all anyway though, as you noticed from my other thread.
User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: How to use Tiled (or not) with a platformer

Post by jojomickymack »

Give this a shot - add a function to the stalker-x library to just return the x, y and scale.

Code: Select all

function Camera:getCoords()
    return self.x, self.y, self.scale
end
in the love.update function, call that function and consume the coordinates

Code: Select all

cameraX, cameraY, cameraScale = camera:getCoords()
and when it comes time to draw, calculate dx and dy for use in translating the map in its draw call based on cameraX and cameraY

Code: Select all

dx = cameraX - (love.graphics.getWidth() / 2) / cameraScale
dy = cameraY - (love.graphics.getHeight() / 2) / cameraScale
and draw the map like so

Code: Select all

map:draw(-dx, -dy, cameraScale, cameraScale)
So far in testing, I see stalker-x's effects working as expected! See if that works for you, hasen.
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to use Tiled (or not) with a platformer

Post by hasen »

jojomickymack wrote: Tue Jan 23, 2018 2:49 pm Give this a shot - add a function to the stalker-x library to just return the x, y and scale.

Code: Select all

function Camera:getCoords()
    return self.x, self.y, self.scale
end
in the love.update function, call that function and consume the coordinates

Code: Select all

cameraX, cameraY, cameraScale = camera:getCoords()
and when it comes time to draw, calculate dx and dy for use in translating the map in its draw call based on cameraX and cameraY

Code: Select all

dx = cameraX - (love.graphics.getWidth() / 2) / cameraScale
dy = cameraY - (love.graphics.getHeight() / 2) / cameraScale
and draw the map like so

Code: Select all

map:draw(-dx, -dy, cameraScale, cameraScale)
So far in testing, I see stalker-x's effects working as expected! See if that works for you, hasen.
I only just noticed your post because it seems I'm not automatically subscribed to my own threads. Thanks I'll see how that works
hasen
Party member
Posts: 157
Joined: Sat Jan 20, 2018 2:01 pm

Re: How to use Tiled (or not) with a platformer

Post by hasen »

Forgot to mention - your code works perfectly. Thanks very much Jojomickymack.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot] and 42 guests