[Solved] Using Box2D with STI
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] Using Box2D with STI
I am trying to make a platformer in which instead of going from left to right you go from bottom to top. I am using Tiled and STI for map making. Please forgive me if this kind of question is answered before, I searched for a long time but found no solution. For physics I tried using Box2D but it is generating wierd results, somtimes not colliding at all (I have added the custom property "collidable" on my layer, and set it to true), sometimes after few seconds. And I have also set the player offset to half the width and half the height (thus centre) to match with x,y of Box2D. Please point out what am I doing wrong and how can I correct it. I have attached a minimal .love file to recreate the problem below. (Left, Right keys for sideways movement, Up arrow key for 'jumping')
Last edited by Paltze on Thu Aug 12, 2021 7:00 am, edited 1 time in total.
Re: Using Box2D with STI
I believe that the problem is that the player is not drawn in the centre of the screen or correctly scaled. It should be centred. If you imagine a box right at the centre of the screen, it works.Paltze wrote: ↑Mon Aug 09, 2021 10:30 am I am trying to make a platformer in which instead of going from left to right you go from bottom to top. I am using Tiled and STI for map making. Please forgive me if this kind of question is answered before, I searched for a long time but found no solution. For physics I tried using Box2D but it is generating wierd results, somtimes not colliding at all (I have added the custom property "collidable" on my layer, and set it to true), sometimes after few seconds. And I have also set the player offset to half the width and half the height (thus centre) to match with x,y of Box2D. Please point out what am I doing wrong and how can I correct it. I have attached a minimal .love file to recreate the problem below. (Left, Right keys for sideways movement, Up arrow key for 'jumping')
Game.love
This fixes that part for me:
Code: Select all
-- change this:
love.graphics.translate(-tx, -ty)
player:draw()
-- to this:
love.graphics.translate(-tx+width/2, -ty+height/2)
player:draw()
Re: Using Box2D with STI
Thank you for helping me. I noticed, after you said, that there is a lot of extra transparent space in sprite. After cropping it out and removing scale, it is working fine. However after applying scale it starts behaving wierdly again. How can I use scale without wierd results?
Re: Using Box2D with STI
Not sure from just the description. I'd suggest to use a box2d visualizer such as https://github.com/airstruck/sketchy to see where the collision boxes are and how they mismatch your expectations.
Re: Using Box2D with STI
Thank you for your help, I was looking for something like that for a long time. It helped in fixing the issues.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests