A variety of questions.

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
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

A variety of questions.

Post by Neon »

1. How do I set the colour of a rectangle to a specific colour, but have text be a different colour.

Code: Select all

function love.draw()
	love.graphics.rectangle("fill", 200, 200, 200, 200)
	love.graphics.setColor(100,100,100)
	love.graphics.print("Test", 500, 500)
end
The above code shows them both as grey. I want just the test to be grey.

2. In the code in question one, I put this line outside the love.draw() function.

Code: Select all

fontsize = love.graphics.newFont(24)
Why wasn't it size 24 font?

3. Must I define the position of a button and check if the cursor is in that area to register if it's clicked? Or is there a better way? If not, what's the best way to manage the method I suggested.

4. What are the most important things to learn in the love API to make a game, so I can learn them first.

5. I was told not to use love.timer.sleep, how else should I stop the program? Should I use love.timer.sleep? Should I have to even stop the program?

Thanks in advance!
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: A variety of questions.

Post by Qcode »

1.

Code: Select all

function love.draw()
   love.graphics.setColor(0, 0, 0)
   love.graphics.rectangle("fill", 200, 200, 200, 200)
   love.graphics.setColor(100,100,100)
   love.graphics.print("Test", 500, 500)
end
All you had to do was set the color twice.

2. You also have to set the fontsize not just make it. Like so

Code: Select all

love.graphics.setFont(fontsize)
3. Like menu buttons? Then I would do it like this, using your rectangle in 1.

Code: Select all

function love.mousepresse(x, y, button)
         if x > 200 and x < 400 and y > 200 and y < 400 then
                  -- Whatever you need to do here
         end
end
4. I don't believe there is any specific api but I would suggest going through all the tutorials then making a game.

5. To Stop the program as in close it you would use

Code: Select all

love.event.push("quit")
wherever you need to quit the game.

Hope that answered all your questions.

Qcode :awesome:
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

Re: A variety of questions.

Post by Neon »

That really helped, I have two last questions.

Say I create a button using the example in one. How can I define it, so I can edit it?

Code: Select all

button = love.graphics.rectangle("fill",200,200)
button.x = 300
I doubt the above code would work, but it is a example. How would I do something like this?

Lastly, how can I manage special function for each button? Such as for when a certain button has the mouse hovered over it, or if it's clicked. How should I manage specific functions that are specific to certain buttons?
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: A variety of questions.

Post by Qcode »

If you wanted to edit it you would probably want to have the button's coordinates in a table like this.

Code: Select all

button = {
                x = 200,
                y = 200,
                width = 200,
                height = 200
           }
function love.draw()
                love.graphics.rectangle("line", button.x, button.y, button.width, button.height)
end
Then if you wanted the button to move when you pressed it you would do something like this.

Code: Select all

function love.mousepressed(x, y, button)
            if x > button.x and x < button.x + button.width and y > button.y and y < button.y + button.height then
                         if button.x == 200 then
                                  button.x = 300
                         elseif button.x == 300 then
                                  button.x = 200
                         end
            end
end
If you click it it moves.

If you wanted to manage specific things for specific buttons, you would use if and elseif like in above. You just have to keep using elseif for each seperate button. For when a mouse is hovering over it then something like this.

Code: Select all

function love.update()
         local x = love.mouse.getX()
         local y = love.mouse.getY()
         if x > button.x and x < button.x + button.width and y > button.y and y < button.y + button.height then
                       if button.x == 200 then
                                button.x = 300
                       elseif button.x == 300 then
                                button.x = 200
                       end
          end
end
If you have any other questions feel free to ask.

Qcode :awesome:
Neon
Prole
Posts: 16
Joined: Sun Apr 01, 2012 3:46 pm

Re: A variety of questions.

Post by Neon »

That really helps! Can you refer me to some awesome tutorials?
User avatar
Qcode
Party member
Posts: 170
Joined: Tue Jan 10, 2012 1:35 am

Re: A variety of questions.

Post by Qcode »

https://love2d.org/wiki/Category:Tutorials

Those are all really good and well explained. I would also recommend unzipping your favorite love games and looking at the code inside to see if you can learn anything.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 5 guests