Newbie question about speed of game

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
mediakitchen
Prole
Posts: 8
Joined: Fri Oct 08, 2010 5:39 am

Newbie question about speed of game

Post by mediakitchen »

Another newbie question.

Only been using Love for a couple of hours and playing around with a simple penalty shootout game idea.

I have managed to work out to detect when the mouse clicks the ball (thanks to help) and I am also able to launch the ball when the mouse is released. I have set the speed of my ball to 1 pixel in the horizontal direction but notice is is flying across the screen.

I would therefore like advice on how best to control the speed of the ball. Do I need to set up some sort of timer, or can I change the FPS or do I just need to change the speed to a smaller value (i.e a decimal less than one).

Thanks

Paul

Here is my entire code so far

Code: Select all


function love.load()
   ball = love.graphics.newImage("ball.png")
   ballx = 100
   bally = 400
   ballHorizontalVelocity = 0
   ballVerticalVelocity = 0
   arrow = love.graphics.newImage("arrow.png")
   arrowx = 150
   arrowy = 150
end

function love.draw()
    love.graphics.draw(ball, ballx, bally)
    love.graphics.draw(arrow, arrowx, arrowy)
   

  
end

function love.update(dt)

	ballx = ballx + ballHorizontalVelocity

end


function love.mousepressed(x, y, button)

   -- Calculate if mouse over ball
   -- i.e distance squared less than radius squared

   local ballRadiusSquared = 900 -- 30 x 30

   if button == 'l' then

      local distanceSquared = distanceSquaredFrom(x,y,ballx + 30,bally + 30)

	if distanceSquared <= ballRadiusSquared then

		arrowx = ballx + 30 -- move arrow to center of ball clicked
      		arrowy = bally + 30 - 7

        end
   end
end


function love.mousereleased(x, y, button)
   if button == 'l' then
      kickBall(x,y) 
   end
end


function kickBall(x,y)
	ballHorizontalVelocity = 1

end



function distanceSquaredFrom(x1,y1,x2,y2)
   return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
end

mediakitchen
Prole
Posts: 8
Joined: Fri Oct 08, 2010 5:39 am

Re: Newbie question about speed of game

Post by mediakitchen »

Following up my previous post I added the following code inside the love.draw function and I am getting a value of around 900. Does that mean I am getting a FPS this high?

Code: Select all


love.graphics.print(love.timer.getFPS( ), 300,300)

User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: Newbie question about speed of game

Post by Thursdaybloom »

Try this:

Code: Select all

function love.update(dt)

   ballx = ballx + ballHorizontalVelocity * dt

end
dt is delta time, which is "Time since the last update in seconds". This will help things run at the same speed regardless of how fast their computer is
mediakitchen
Prole
Posts: 8
Joined: Fri Oct 08, 2010 5:39 am

Re: Newbie question about speed of game

Post by mediakitchen »

Thanks ThursdayBloom

That works a treat.

Many thanks

Paul
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests