I DID look at other code, but its always way too overcomplicated(i think?)
whats the simplest way?
How do you simple make a button?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How do you simple make a button?
You need x and y coordinates to position the button, and a width and height to give it some substance.
You then use the mousepressed function to check if the location of the mouse when it was pressed lies within the confines of your button. If you load an image, and set it to the same position and size, it will show people where to click.
You then use the mousepressed function to check if the location of the mouse when it was pressed lies within the confines of your button. If you load an image, and set it to the same position and size, it will show people where to click.
Re: How do you simple make a button?
so actualy have to make some collision detection with a mouse and a image :O?
thats pretty sad 3:
why can't LÖVE ad a function like when an image can mousepressed? =
image = blabla image
image.MousePressed:connect()
thats pretty sad 3:
why can't LÖVE ad a function like when an image can mousepressed? =
image = blabla image
image.MousePressed:connect()
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: How do you simple make a button?
LOVE tries to stay relatively low level. It also doesn't try to create a single solution for everybody's problems. Everyone has different needs.GijsB wrote:so actualy have to make some collision detection with a mouse and a image :O?
thats pretty sad 3:
why can't LÖVE ad a function like when an image can mousepressed? =
image = blabla image
image.MousePressed:connect()
On a different note, the community is here to help. (as kraftmen so kindly spent time doing already)
And we help a lot.
Re: How do you simple make a button?
oh and, is there any way i can optimise my code?(its a base of a puzzle game im making) =
diffeculty = 7
size = 500/diffeculty--logic
BOXES = {}
math.randomseed(os.time())
for x = 1,diffeculty do
for y = 1,diffeculty do
BOX = {O = math.random(0,1), X = x, Y = y}
table.insert(BOXES,BOX)
end
end
function findnumberx(x)
n = ""
c = 0
for i,v in pairs(BOXES) do
if v.X == x then
if v.O == 1 then
c = c+1
else
if c > 0 then
n = n..tostring(c)..","
end
c = 0
end
end
end
if c > 0 then
n = n..tostring(c)..","
end
return n
end
function findnumbery(y)
n = ""
c = 0
for i,v in pairs(BOXES) do
if v.Y == y then
if v.O == 1 then
c = c+1
else
if c > 0 then
n = n..tostring(c)..","
end
c = 0
end
end
end
if c > 0 then
n = n..tostring(c)..","
end
return n
end
function love.draw()
for i,v in pairs(BOXES) do
love.graphics.draw(love.graphics.newImage("BUTTONOFF.png"),v.X*size,v.Y*size,0,size/30,size/30,0,0)--30 pixels width images, so size/pixels
end
for x = 1,diffeculty do
love.graphics.print(findnumberx(x), x*size, size-30)
end
for y = 1,diffeculty do
love.graphics.print(findnumbery(y), size-30, y*size)
end
end
diffeculty = 7
size = 500/diffeculty--logic
BOXES = {}
math.randomseed(os.time())
for x = 1,diffeculty do
for y = 1,diffeculty do
BOX = {O = math.random(0,1), X = x, Y = y}
table.insert(BOXES,BOX)
end
end
function findnumberx(x)
n = ""
c = 0
for i,v in pairs(BOXES) do
if v.X == x then
if v.O == 1 then
c = c+1
else
if c > 0 then
n = n..tostring(c)..","
end
c = 0
end
end
end
if c > 0 then
n = n..tostring(c)..","
end
return n
end
function findnumbery(y)
n = ""
c = 0
for i,v in pairs(BOXES) do
if v.Y == y then
if v.O == 1 then
c = c+1
else
if c > 0 then
n = n..tostring(c)..","
end
c = 0
end
end
end
if c > 0 then
n = n..tostring(c)..","
end
return n
end
function love.draw()
for i,v in pairs(BOXES) do
love.graphics.draw(love.graphics.newImage("BUTTONOFF.png"),v.X*size,v.Y*size,0,size/30,size/30,0,0)--30 pixels width images, so size/pixels
end
for x = 1,diffeculty do
love.graphics.print(findnumberx(x), x*size, size-30)
end
for y = 1,diffeculty do
love.graphics.print(findnumbery(y), size-30, y*size)
end
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How do you simple make a button?
You don't have to worry about optimization, especially not now. Try finishing your game first, since that is much more important.
Help us help you: attach a .love.
Re: How do you simple make a button?
umm my collision detection doesnt work 3:
local ap = {x = v.X, y = v.Y}
local as = {x = size, y = size}
local bp = {x = mx, y = my}
local bs = {x = 1,y = 1}
E = ap.x + as.x > bp.x and bp.x + bs.x > ap.x and ap.y + as.y > bp.y and bp.y + bs.y > ap.y
gives wrong answer
v is a table of the position of the image, and mx and my are mouse positions
local ap = {x = v.X, y = v.Y}
local as = {x = size, y = size}
local bp = {x = mx, y = my}
local bs = {x = 1,y = 1}
E = ap.x + as.x > bp.x and bp.x + bs.x > ap.x and ap.y + as.y > bp.y and bp.y + bs.y > ap.y
gives wrong answer
v is a table of the position of the image, and mx and my are mouse positions
Re: How do you simple make a button?
First of all, use code blocks here in the forums when you post code, makes it easier to read (and keeps indentation). You use it like this:
[code]code here[/code]
[code]code here[/code]
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How do you simple make a button?
Code: Select all
local inBox = mx > v.x and my > v.y and mx < v.x+size and my < v.y+size
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 6 guests