Background image. I'm stuck, need help
Posted: Fri Jun 25, 2021 7:12 am
I have functions:
In love.Load I added backgroundofMenu = love.graphics.newImage("/graphics/123.bmp").
When I add code love.graphics.draw(backgroundofMenu,0,0) in "love.draw()" before cycle - image shows only first frame. If I add love.graphics.draw(backgroundofMenu,0,0) in update-function - Nothing happens.
If I add in myButton:draw() before all the code - all menu buttons are no longer displayed except exit.
How can I add the background image?
Code: Select all
function love.draw()
for n, myButton in ipairs (buttons) do
myButton:draw()
end
end
Function code of myButton:draw() :
function myButton:draw()
if self.isHover then
love.graphics.setColor(self.HoverColor)
if currentStateMouse == true then
love.graphics.setColor(self.chooseColor)
end
else
love.graphics.setColor(self.color)
end
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
love.graphics.setColor(0,0,0)
love.graphics.print(self.text,self.x,self.y+2)
end
return myButton
end
function myButton:update(dt)
mouse = {}
mouse.x,mouse.y = love.mouse.getPosition()
currentStateMouse = love.mouse.isDown(1)
self.isHover = mouse.x >= self.x and mouse.x <= (self.x + self.width) and
mouse.y >= self.y and mouse.y <= (self.y + self.height)
if self.isHover and currentStateMouse == true
and self.oldStateButton == false
then
print("It's a button - ", p.text)
love.graphics.setColor(self.chooseColor)
if p.text=="Exit" then -- выход из игры по кнопке
love.quit()
end
if p.text=="New Game" then -- Начало игры
print("LOADING...")
love.game()
end
if p.text=="Options" then -- Настройки
print("Settings")
end
end
self.oldStateButton = currentStateMouse
end
When I add code love.graphics.draw(backgroundofMenu,0,0) in "love.draw()" before cycle - image shows only first frame. If I add love.graphics.draw(backgroundofMenu,0,0) in update-function - Nothing happens.
If I add in myButton:draw() before all the code - all menu buttons are no longer displayed except exit.
How can I add the background image?