External factors breaking ingame things?

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
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

External factors breaking ingame things?

Post by Sarcose »

Hey guys. I've been noticing that when I drag the window of my game, it breaks the collision detection for my shitty little platformer, by causing the hero to fall through the floor. I assumed that would be something I could deal with as I learn more about what I'm doing. Then today I had Tiled open, and everything started getting really wonky -- collision wasn't running properly, and the player was stuttering all around as if velocity was being applied to it over and over (there is a redundant velocity application in that it uses a collider:move (in hardon collider) check to continually check for ground, as I haven't looked further into the library to find a better implementation). I was completely panicked until I realized that closing Tiled fixed the problem.

Any clues as to the possible source of either of these problems? I'll upload my project but I was hoping this was a common problem for newbie lovers considering the project started from a tutorial.

My code is spaghetti and I'm sure you will despise it if you try to look too far into it. The little version number commenting practice at the top is surely very cringe-worthy too. I have yet to learn version control and multiple source files.
Attachments
Sarcose Platformer 0.10.love
(71.01 KiB) Downloaded 81 times
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: External factors breaking ingame things?

Post by TurtleP »

One thing I do in my projects to prevent the first issue is:

Code: Select all

function love.update(dt)
 dt = math.min(1/60, dt)
 --other code
end
I've never used anything other than my own physics module so I probably can't help you with the tiled issue :(
User avatar
raingloom
Prole
Posts: 36
Joined: Wed Apr 22, 2015 12:35 am
Location: Always elsewhere

Re: External factors breaking ingame things?

Post by raingloom »

I'm having no problems running your demo on Linux (using i3 for window management). Scaling, translating or focus changes don't seem to affect physics.
I suspect that whatever your OS uses for window management disables rendering/updating when moving or resizing windows and when Löve gets to update it again, the delta time is huge, so your physics go crazy.
Try logging or graphing your fps and/or update delta time and see if there is a correlation between your problem and any lag.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: External factors breaking ingame things?

Post by Nixola »

Windows locks LÖVE when moving the window, so that's your issue. As TurtleP, the only way to prevent this is limiting dt, although I'd limit it to 1/30 or 1/20 or something, to allow people to play at full speed even if they can't run the game at full FPS.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: External factors breaking ingame things?

Post by Jasoco »

Agreed. It's the best way to make sure. Windows pauses the runtime when moving the window and OS X pauses it when pressing down on the X, _ and + buttons (But not when moving the window.) And I suspect both as well as Linux pause it when resizing.

Just limit dt and don't base anything important to timing on the running os.time or love.timer.getTime and instead have your own timer internally that bases itself on the passed dt. (Anecdote: A while ago someone created a Runner game that based its level length on the system timer, so if you held the mouse down on the titlebar/buttons to pause Löve's execution, you could beat any level by holding it down for a few seconds. Had it been based on an internal variable instead, that wouldn't happen.)

dt = math.min(1/15, dt)

(Where 15 is the minimum framerate you'd want. I think 15 is reasonable. Note that if the FPS actually goes below 15, then there'll be visual slowdown, but really, that's a worst case scenario.)
Sarcose
Prole
Posts: 48
Joined: Wed Jul 08, 2015 12:09 am

Re: External factors breaking ingame things?

Post by Sarcose »

Thanks, guys. That's some really useful information to know, I appreciate it.
Post Reply

Who is online

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