How to use Tiled (or not) with a platformer
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to use Tiled (or not) with a platformer
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?
- jojomickymack
- Prole
- Posts: 45
- Joined: Tue Dec 26, 2017 4:52 pm
Re: How to use Tiled (or not) with a platformer
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.
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.
Re: How to use Tiled (or not) with a platformer
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.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.
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.
Re: How to use Tiled (or not) with a platformer
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.
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.
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.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.
Re: How to use Tiled (or not) with a platformer
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).
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).
Re: How to use Tiled (or not) with a platformer
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.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).
- jojomickymack
- Prole
- Posts: 45
- Joined: Tue Dec 26, 2017 4:52 pm
Re: How to use Tiled (or not) with a platformer
Give this a shot - add a function to the stalker-x library to just return the x, y and scale.
in the love.update function, call that function and consume the coordinates
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
and draw the map like so
So far in testing, I see stalker-x's effects working as expected! See if that works for you, hasen.
Code: Select all
function Camera:getCoords()
return self.x, self.y, self.scale
end
Code: Select all
cameraX, cameraY, cameraScale = camera:getCoords()
Code: Select all
dx = cameraX - (love.graphics.getWidth() / 2) / cameraScale
dy = cameraY - (love.graphics.getHeight() / 2) / cameraScale
Code: Select all
map:draw(-dx, -dy, cameraScale, cameraScale)
Re: How to use Tiled (or not) with a platformer
I only just noticed your post because it seems I'm not automatically subscribed to my own threads. Thanks I'll see how that worksjojomickymack 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.
in the love.update function, call that function and consume the coordinatesCode: Select all
function Camera:getCoords() return self.x, self.y, self.scale end
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 cameraYCode: Select all
cameraX, cameraY, cameraScale = camera:getCoords()
and draw the map like soCode: Select all
dx = cameraX - (love.graphics.getWidth() / 2) / cameraScale dy = cameraY - (love.graphics.getHeight() / 2) / cameraScale
So far in testing, I see stalker-x's effects working as expected! See if that works for you, hasen.Code: Select all
map:draw(-dx, -dy, cameraScale, cameraScale)
Re: How to use Tiled (or not) with a platformer
Forgot to mention - your code works perfectly. Thanks very much Jojomickymack.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 3 guests