Today I tested my game on a friend’s computer, and it appears that the computer in question is far more powerful than mine
On my computer:
On his computer:
I don’t have any gameplay footage to show the visual result, but the characters were moving way faster (while the spine animation seemed to remain the same).
It’s been a while, but… it seems like I’m using something called “Metrics” (?) to display the FPS.
The code looks like this:
function init(self)
self.instance = fps.create(self.samples, nil, go.get_world_position(), self.color)
end
function update(self, dt)
self.instance.update()
if self.show then
self.instance.draw()
end
fps.update()
debug.fps = lume.round(fps.fps(), 1)
end
And for the the characters movements:
function update(self, dt)
local p, movement = go.get_world_position(), self.move_direction * self.move_speed_cur * move_speed_factor
go.set_position(p + movement)
end
1/ Is it possible to prevent the game from going beyond 60fps?
2/ And most of all, how to make sure the character movements don’t depend on the fps? (so they don’t move slowly at 30fps and super fast at 120fps)
Your movement calculation should use the delta time which is passed into the update function. This allows you to account for how much time each frame is actually taking.
Just added *dt at the end (like in the movement tutorial) but the characters don’t move anymore (looks like it somehow “neutralizes” the movement vector).
function update(self, dt)
local p, movement = go.get_world_position(), self.move_direction * self.move_speed_cur * move_speed_factor * dt
go.set_position(p + movement)
end
If you didn’t change your speed value, then you have effectively reduced speed to 1/60th of what you are used to seeing. Think of the speed value as “pixels per second” (currently it is “pixels per frame”).
Multiplying your movement speed by dt changes the meaning from units/frame to units/second. So if your speed was 10 pixels per frame, it’s now 10 pixels per second which is much slower. You’ll need to increase your speed values accordingly (multiplying it by 60 should put it back to normal).