How do objects in the game work properly with the time that the game runs?

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
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

How do objects in the game work properly with the time that the game runs?

Post by ilovelove2019 »

Hey guys! I am making a platform game with bump. I encountered a situation with my method of jumping. Each time the player presses 'w' the character will jump (I put self.vy = -370), and in the Player: update (dt) function I have the command that if self.vy <200 is self.vy = self .vy + 20. Because I use bump for collision, when the player touches the ground, he will stop himself, I don't need to make self.vy = 0.

Everything was pretty stable, until I added a lot of objects to my game, a few hundred objects (I made the money drop every time the player punched an enemy). My game started to become more laggy and each character's jump was many times higher than normal (2 or 3 times higher). How to fix this error? I want when my game becomes laggy, the characters still jump as high as before.
And from this issue I started thinking about my game performance. There were only about 300-400 objects in the game right now, but it was starting to lag. Well, to put it further, every time I run the code my character is first affected by gravity and falls, but for 1 second all the objects stay still, I think it is lag, or is it initializing the game's initial objects and then running a few seconds later, I don't want the delay (I wonder if my computer configuration is weak or not?
32 bit, RAM: 2GB, Processor: 2.6Hz). In the future, I plan to create a full map and then move the camera along with the character, but given the current situation, it is probably impossible. I would like to ask more about your game, how many objects exist at the same time? And with a game, how many objects co-exist as well? I used to think about splitting the map, each part about 3 to 4 screens, when the character went over that area, delete that area then save it to the data file of the area that went through and Draw a new zone. But that is a bit difficult, I think it initialized like minecraft, but my map is limited. Because of the complexity, I haven't done it yet, it would be nice if you could share more with me about this.
Above are my questions, please answer me, I am very thankful to you.
MrFariator
Party member
Posts: 510
Joined: Wed Oct 05, 2016 11:53 am

Re: How do objects in the game work properly with the time that the game runs?

Post by MrFariator »

The jumping issue has to do with how lag will affect how often love.update gets called. You either need to rework your jumping code to work with varying delta times (the 'dt' parameter love.update receives), or you can fix your timestep. I personally do the latter, using rxi's tick library.

For the second part I can not tell without seeing some code. 400 objects doesn't seem unreasonable, even for the specs of your computer, so this may very well be just your code doing too much work every time love.update or love.draw gets called.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: How do objects in the game work properly with the time that the game runs?

Post by ivan »

For most games you are rarely going to have more than a few hundred sprites moving on the screen at the same time.
If you want to make large levels with thousands of objects then you absolutely have to partition the level into sections.
This is not easy to do in a clean, generic way.
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

Re: How do objects in the game work properly with the time that the game runs?

Post by ilovelove2019 »

I say many of those objects are my tilemap, I build a full map, it's the platform blocks that collide with players and other objects, those blocks are static, I don't know if they count as affecting performance. or not? Besides, about jumping, I find it only fails when the number of objects appearing (namely the coins bouncing on the ground I'm doing) exceeds a certain number, about 140, before That's fine, the player's height can still jump normally, although there is lag, but he still preserves the height when jumping, but when he surpasses that number, the height of the jump increases by 2 times, meanwhile height when jumping suddenly increases rather than slowly increasing with lag. Can you show me how to create the jump method for the player? I need a standard way, I need an algorithm. Thank you very much.
User avatar
4vZEROv
Party member
Posts: 126
Joined: Wed Jan 02, 2019 8:44 pm

Re: How do objects in the game work properly with the time that the game runs?

Post by 4vZEROv »

You need to multiply every number that you use for movement by dt so it's framerate independant.
Or you need to lock the framerate (look at gameloop accumulator)
ilovelove2019
Citizen
Posts: 78
Joined: Wed Sep 11, 2019 10:38 am

Re: How do objects in the game work properly with the time that the game runs?

Post by ilovelove2019 »

Do I need to multiply self.vx, vy for dt? I see bump already in the user guide already.

Code: Select all

function movePlayer(player, dt)
  local goalX, goalY = player.x + player.vx * dt, player.y + player.vy * dt
  local actualX, actualY, cols, len = world:move(player, goalX, goalY)
  player.x, player.y = actualX, actualY
  -- deal with the collisions
  for i=1,len do
    print('collided with ' .. tostring(cols[i].other))
  end
end
https://github.com/kikito/bump.lua
Post Reply

Who is online

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