lag using love.physics

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
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

lag using love.physics

Post by Doctory »

I've been fixing up an old platformer I found and I happened to stumble upon some extreme lag.
First there's no lag, then it increases by time.
Hope you can fix it.
Attachments
platformer.love
laggy
(2.27 KiB) Downloaded 76 times
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: lag using love.physics

Post by Doctory »

I do realize this is a double post, but I'M LOSING MY PATIENCE!
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: lag using love.physics

Post by Azhukar »

You are creating thousands of new bodies, fixtures and shapes each second.

Code: Select all

function love.draw()
...
rect.body = love.physics.newBody(world, x * 20, y * 20, "static")
rect.shape = love.physics.newRectangleShape(20, 20)
rect.fixture = love.physics.newFixture(rect.body, rect.shape)
...
end
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: lag using love.physics

Post by Doctory »

Azhukar wrote:You are creating thousands of new bodies, fixtures and shapes each second.

Code: Select all

function love.draw()
...
rect.body = love.physics.newBody(world, x * 20, y * 20, "static")
rect.shape = love.physics.newRectangleShape(20, 20)
rect.fixture = love.physics.newFixture(rect.body, rect.shape)
...
end
How do I fix this?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: lag using love.physics

Post by Plu »

Create the bodies, shapes and fixtures only once (probably in love.load or some other loading function) and then keep using those.

The same way you'd do it with images and sounds and the like; store the return value from the creator function and keep using it.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: lag using love.physics

Post by Doctory »

Plu wrote:Create the bodies, shapes and fixtures only once (probably in love.load or some other loading function) and then keep using those.

The same way you'd do it with images and sounds and the like; store the return value from the creator function and keep using it.
OK, so I did that now, but the problem is it only draws the last block. How do I make it so it draws them all?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: lag using love.physics

Post by bartbes »

Doctory wrote:I do realize this is a double post, but I'M LOSING MY PATIENCE!
It was 4 hours. Calm down.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], YaCy [Bot] and 2 guests