I am trying to make a basic menu using functions and I sure I am using them wrong, mostly because it does not work. I have no idea how to google this so I need your help!
function love.load()
carregarButons();
end
function love.draw()
imprimirButons()
end
function love.update()
comprobarRatoliPos();
end
function carregarButons()
butonsImg = {
love.graphics.newImage("/Images/mainMenu/botoJugar/V2/botoJugar.png"), love.graphics.newImage("/Images/mainMenu/botoJugar/V2/botoJugar2.png"), 100, 200 -- buto Jugar
};
estatButoJugarActual = 1;
end
function imprimirButons()
if estatButoJugarActual == 1 then
love.graphics.newImage("Images/mainMenu/botoJugar/V2/botoJugar2.png");
love.graphics.draw( butonsImg[2], 100, 200 );
else
b = love.graphics.newImage("Images/mainMenu/botoJugar/V2/botoJugar.png");
love.graphics.draw( b, 100, 200 );
end
end
function comprobarRatoliPos()
mouseX, mouseY = love.mouse.getPosition();
if mouseX > 100 and mouseX < 350 and mouseY > 200 and mouseY < 270 then
estatButoJugarActual = 2;
else
estatButoJugarActual = 1;
end
end
As you can see, I tried various things in the imprimirButons() function. The first love.graphics.draw() does not work while the second does but I want the first one to work.
The "love.graphics.newImage("Images/mainMenu/botoJugar/V2/botoJugar2.png");" on line 23 doesn't do anything, you should remove it. It constantly loads a file from disk and then discards it, which is bad for your overal performance.
Other than that I'm not really sure what is going wrong. If I load this code, then it works just fine? At least; it's not showing any errors.
(Also, if you want help from the international community it helps to put your variables and functions in english, although I don't know if you english is good enough for it. While I can figure out what this is supposed to do, if it gets more complex it'll be pretty much impossible for me and other non Spanish? speakers to understand.)
function love.load()
loadButtons();
end
function love.update()
checkMousePos();
end
function loadButtons()
buttonsImg = {
love.graphics.newImage("/Images/mainMenu/playButton/V2/playButton.png"), love.graphics.newImage("/Images/mainMenu/playButton/V2/playButton2.png"), 100, 200 -- buto Jugar
};
playButtonActualState= 1;
end
function drawButtons()
if playButtonActualState== 1 then
love.graphics.draw( butonsImg[2], 100, 200 );
else
b = love.graphics.newImage("Images/mainMenu/playButton/V2/playButton.png");
love.graphics.draw( b, 100, 200 );
end
end
function checkMousePos()
mouseX, mouseY = love.mouse.getPosition();
if mouseX > 100 and mouseX < 350 and mouseY > 200 and mouseY < 270 then
playButtonActualState = 2;
else
playButtonActualState = 1;
end
end
The error I get is the same. Something that I find revelant is that I am using main.lua and menu.lua. The main.lua is this: