Mrs.mewis
Mrs.mewis

Reputation: 21

image not loading over others in pause state

I am trying to create a pause function in my CS50G fifty-bird problem set. However, the image I have to come up is behind the pipes and bird when it is rendered. I am new to using Love2d and Lua but I am not finding any documentation on how to move an image to the front when a key is pressed.

function PlayState:update(dt)
   
    if love.keyboard.wasPressed('p') then

        if self.pause then
            self.pause = false
            scrolling = true
            sounds['music']:play()
            sounds['pause']:pause()
        else
            self.pause = true
            scrolling = false
            sounds['music']:pause()
            sounds['pause']:play()

        end
        
    end

    if not self.pause then
   
    function PlayState:render()
        for k, pair in pairs(self.pipePairs) do
            pair:render()
        end
        if self.pause then
            love.graphics.draw(pause, 235, 100, center)
        end

        love.graphics.setFont(flappyFont)
        love.graphics.print('Score: ' .. tostring(self.score), 8, 8)
    
        self.bird:render()

I have messed around with the code a bit and tried moving the picture to main.lua but that did not work either, or I just did it wrong.

Upvotes: 2

Views: 66

Answers (1)

ggorlen
ggorlen

Reputation: 57115

Converting my comment to an answer...

Drawing occurs in layers from bottom to top, so moving the pause drawing code after other entities you're drawing should place it in a layer above them:

-- ...
for k, pair in pairs(self.pipePairs) do
    pair:render()
end

love.graphics.setFont(flappyFont)
love.graphics.print('Score: ' .. tostring(self.score), 8, 8)

self.bird:render()

if self.pause then -- moved down to bottom
    love.graphics.draw(pause, 235, 100, center)
end
-- ...

Upvotes: 3

Related Questions