I have 2 questions here:
I have a widget button on screen, each time I tap it, a cat on the screen will jump…
So basically I wrote 3 code blocks from top to bottom:
-
gameOver() code – disable the jumpButton, show highScore and a “replay” button.
-
catJump() code – jump the cat. If cat hits something, it dies and call the gameOver() code.
-
widget.newButton code --initialize a jump button to let the player click. onEvent is set to catJump()
Question No.1:
The catJump function code has to be put before the widget.newButton code, else there will be an error.
When the cat dies, I need to disable the jumpButton. I need to insert this code:
jumpButton:setEnabled(false)
before the widget.newButton codes, (inside the gameOver() function). But I get an error saying "attempt to index global ‘jumpButton’ (a nil value)
So I guess putting jumpButton methods anywhere before the jumpButton initializing codes will have errors.
How do I make fix this problem?
Question No.2:
When the cat jump, I have a cat-jumping sprite playing. I set it to play in 500 milliseconds.
During this 500 milliseconds, I need to disable the jumpButton. (Or else the cat will jump again in mid air)
Only when the sprite finish playing, jumpButton is enabled back.
How do I do this? I still have the problem of where to place the “setEnabled” codes because I always got error of “nil value”.
Help very much appreciated.