I started making games in Löve 2 weeks before and it's amazing!
My only problem is that in my platformer that has been written 48 hours, I have issues regarding the Fps (dt exactly),
trying out multiple solutions and limiting the fps didn't work, so here's my crappy OOP code:
function Player:handleInput(dt)
if self.onGround==false then
if self.velocity.y<400 then
self.velocity.y=self.velocity.y+1
end
else
self.velocity.y=0
end
self.TLbind:update()
if self.control.left and not self.hitLeft then
if self.onGround then
self.velocity.x=-200
else
self.velocity.x=-150
end
elseif self.control.right and not self.hitRight then
if self.onGround then
self.velocity.x=200
else
self.velocity.x=150
end
else
self.velocity.x = self.velocity.x * (1 - math.min(dt*10, 1))
end
if self.control.jump and self.onGround then
self.velocity.y=-300*dt
self.onGround=false
end
if self.control.tap.menu then
self:die()
end
end
function Player:stayInScreen(dt)
local center=self.body:center()
if center.x-16+self.velocity.x*dt<=0 or center.x+16+self.velocity.x*dt>=650 then
self.velocity.x=0
end
if center.y-16>650 then
self:die()
elseif center.y-16+velocity.y*dt<=0 then
self.velocity.y=0
end
end
function Player:move(dt)
self.body:move(self.velocity.x*dt,self.velocity.y*dt)
self.leg:move(self.velocity.x*dt,self.velocity.y*dt)
self.left:move(self.velocity.x*dt,self.velocity.y*dt)
self.right:move(self.velocity.x*dt,self.velocity.y*dt)
self.head:move(self.velocity.x*dt,self.velocity.y*dt)
end
My issue is that on my low-end laptop the game runs just fine, but on my friend's High-end pc the player jumps to the top of the screen. Please help!
function love.load()
-- this is the first step for limiting the fps
min_dt = 1/60 -- <-- WITH THIS YOU GET 60FPS. You can change it to whatever you want.
next_time = love.timer.getMicroTime()
<YOUR CODE>
end
--********************************************************
-- love.update
--********************************************************
function love.update(dt)
next_time = next_time + min_dt -- second step for fps limit
<YOUR CODE>
end
--********************************************************
-- love.draw
--********************************************************
function love.draw()
<YOUR CODE>
-- last step to limit the fps
local cur_time = love.timer.getMicroTime()
if next_time <= cur_time then
next_time = cur_time
return
end
love.timer.sleep(1000*(next_time - cur_time))
end
And yes, LÖVE is amazing
Last edited by molul on Tue Feb 21, 2012 5:35 pm, edited 1 time in total.
You're suppose to put the logic in love.update, and use its dt argument to scale your movement.
If you want to move 5 pixels per second, you add (or subtract) 5*dt, according to:
Actually I was already using dt in my love.update.
This is funny. I added those lines to one of my first programs when I was just starting learning LÖVE, and I kept them until now. Later I learnt love.graphics.setMode() and how to initialize the window from the conf.lua file, so I was setting vsync On, which resulted in having 60fps already. I've just removed those lines I posted two posts ago and it works exactly the same (lol).
Well, it's always good to remove unneccessary parts of my code. Thanks a lot everybody!
I implemented the 60 fps limit, but it screwed up the collision detection and i had to use very high values for movement.
This method doesn't seems to be working for me... so I'm posting the .love file:
Please someone could give any general tips on the code (i would like to have that functionality to make the players stick to the platforms they are standing on), I'm just 16 and started writing Lua games after C#, C++ and Python last week.