Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Text is not getting removed after clicking
Started by Rodayan Dec 22 2018 04:04 PM

1 reply to this topic
text function remove pause
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Rodayan

[GLOBAL: userInfoPane.html]
Rodayan
  • Observer

  • 9 posts
  • Corona SDK

Hi there,

I added a Pause button, before realising that sometimes you can't tell if it's paused or not. So I went to add text that says "Paused", to the right of the pause button. Done.

Now, it isn't being removed when I unpause the game... even though the display.remove (pauseText) line is there. Repeatedly clicking the button makes new text over the old text (making it bolder).

 

So I want to remove this text!

 

It would be even better if I could change the button which says "Pause", for which the event listener click runs the gamePause function, to "Paused" when it is paused and "Pause" when not paused.
 

 

 

Here's my code:

 

local function gamePause( event )
    if event.phase == "began" then
        if gamePaused == false then
             physics.pause()
             timer.pause( gameLoopTimer)
             local pauseText = display.newText("Paused", display.contentCenterX + 200, 920, native.systemFontBold, 40 )
             gamePaused = true
        elseif gamePaused == true then
             physics.start()
             timer.resume( gameLoopTimer)
             display.remove ( pauseText )
             gamePaused = false
        end
   end
end
 



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,959 posts
  • Corona SDK

this is a scoping issue.  this will work

local pauseText = display.newText("Pause", display.contentCenterX + 200, 920, native.systemFontBold, 40 )
pauseText.isVisible = false  <-- remove this to have the button there all the time

local function gamePause( event )
    if event.phase == "began" then
        gamePaused = not gamePaused
   	if gamePaused then
		physics.pause() 
		timer.pause( gameLoopTimer) 
		pauseText:setText("Paused")
	else 
		physics.start() 
		timer.resume( gameLoopTimer) 
		pauseText:setText("Pause")
	end 
	pauseText.isVisible = gamePaused  <-- remove this to have the button there all the time
    end 
end



[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: text, function, remove, pause