To remove do this;
leftButton:removeEventListener("touch", touchLeft)
For each event.
For your pause button, is it sprite with only two frames? If so it makes more sense to set the current frame than do prepare/play each time.
This little article on flags has an example of toggling a value on and off; http://techority.com/2011/10/30/flags-what-and-why/
Peach :)
PS - Are you using "tap" or "touch" in the event listener for the pause? Don't use touch unless you're specifying an event phase also, else it will fire twice, once on press and once on release.
I'm using the same sprite sheet for the pause button and the left and right buttons. Also, I'm using "tap".
The pause button isn't working like it should. For some reason, the listeners aren't removed and the pig somehow speeds up. :/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| local isPaused = false
local function pauseGame()
isPaused = not isPaused
if (isPaused) then
pauseButton:prepare("pausep")
pauseButton:play("pausep")
piggyBank:addEventListener("collision", piggyBank)
leftButton:addEventListener("touch", touchLeft)
rightButton:addEventListener("touch", touchRight)
Runtime:addEventListener("enterFrame", movePiggyBank)
Runtime:addEventListener("touch", stopPiggyBank)
else
pauseButton:prepare("pausen")
pauseButton:play("pausen")
piggyBank:removeEventListener("collision", piggyBank)
leftButton:removeEventListener("touch", touchLeft)
rightButton:removeEventListener("touch", touchRight)
Runtime:removeEventListener("enterFrame", movePiggyBank)
Runtime:removeEventListener("touch", stopPiggyBank)
end
end
leftButton:addEventListener("touch", touchLeft)
rightButton:addEventListener("touch", touchRight)
Runtime:addEventListener("enterFrame", movePiggyBank)
Runtime:addEventListener("touch", stopPiggyBank)
pauseButton:addEventListener("tap", pauseGame) |
Plug and play code would help. Any errors?
For the timer give it a name;
myTimer = timer.performWithDelay(math.random(750, 1500), createProjectiles, 0)
Then cancel it by doing timer.cancel(myTimer)
When you're a subscriber you'll be able to pause and resume timers, which is much easier for pausing/unpausing.
Peach.
I finally got it! Thanks!