making a pause function

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
Accelerator
Prole
Posts: 3
Joined: Wed Oct 02, 2019 9:56 pm

making a pause function

Post by Accelerator »

I am trying to make a replica of Flappy Bird. One part of the assignment is to make a pause function. I have implemented one but it does not work in the game. Here is the code.

Code: Select all

PauseState = Class{__includes = BaseState}

function PauseState:init()
    self.timer = 0
    self.enterParams = {}
end

function PauseState:update(dt)
    self.timer = self.timer + dt
    
    if love.keyboard.wasPressed('enter') or love.keyboard.wasPressed('return') then
        self.enterParams = {
            ['bird'] = self.bird,
            ['pipePairs'] = self.pipePairs,
            ['timer'] = self.timer,
            ['score'] = self.score
        }
        self.timer = self.timer + 10

        gStateMachine:change('play', self.enterParams)   
    end
end

function PauseState:enter(enterParams)

    scrolling = false
    self.bird = enterParams.bird
    self.pipePairs = enterParams.pipePairs
    self.timer = enterParams.timer
    self.score = enterParams.score
end

function PauseState:render()
    love.graphics.setFont(flappyFont)
    love.graphics.printf('The game paused!', 0, 64, VIRTUAL_WIDTH, 'center')

    love.graphics.setFont(mediumFont)
    love.graphics.printf('Press Enter to continue', 0, 100, VIRTUAL_WIDTH, 'center')
    love.graphics.print(self.timer .. tostring(self.score), 8, 38)
end
JJSax
Prole
Posts: 47
Joined: Fri Apr 04, 2014 3:59 am

Re: making a pause function

Post by JJSax »

WIthout really going through it, most likely if you made it as below it would stop it. You may have to do the same with the line below that adds 10 to self.timer too

Code: Select all

self.timer = self.timer + dt * 0
edit: 0 can be whatever variable obviously to speed/slow time.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: making a pause function

Post by raidho36 »

Pausing basically means not updating the gamestate. So you can put your gamestate update function in an if-case that checks against the pause flag.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 0 guests