I’m working on an iOS game where a text label appears and the player must hit the corresponding colored button. I’m trying to figure out how to format the if statement for recognizing if the button pressed is a match to the current text on screen. What I’m wanting to happen in this if statement is: if redText is showing AND redButton is pushed, add points. Otherwise game over. I’ll copy/paste this statement for each of the four colors.
Here’s the method as I have it currently, note “buttonPressed” means nothing, just a placeholder:
-(void)gameStatePlayNormal
{
if (redText.hidden=NO && buttonPressed == redButton)
{
score += 10;
}
else
{
gameState = kStateGameOver;
}
}
Thanks in advance for your feedback. 🙂
You need to make a function that will be called when any of the buttons are pressed. Hook each button up to this function in your storyboard (“Touch Up Inside” event). Then you can intercept the sender.