I am so confused. I have tried everything I can think of.
Can someone help me out with scoring,
I want it so every time someone touches the screen, a UILabel (player_Score) increases by one number every touch.
Could someone post the code?
Sorry, I am new to Xcode and everything.
You could use this.
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//called whenever someone touches screen
UITouch *touch = [[event allTouches] anyObject];
//setup an int score in .h and use it like this
score += 1;
//setup a label and string that the label displays
NSString *string = [[NSString alloc] initWithFormat:@"%d", score];
// make a label called label
label.text = string;
[string release];
}
Hope this helps
Last edited by Mjsdabeast; 06-13-2010 at 04:55 PM.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//called whenever someone touches screen
UITouch *touch = [[event allTouches] anyObject];
//setup an int score in .h and use it like this
score += 1;
//setup a label and string that the label displays
NSString *string = [[NSString alloc] initWithFormat:@"%d", score];
// make a label called label
label.text = string;
[string release];
}
Hope this helps
Thank you! Just one question, when I touch it, it goes up by 4, not 1. Is that part of the code that you gave me, or is it something in mine?
Yeah. I looked through all the code, nothing to do with a 4. I have also tried:
Code:
score += 0.25;
But it had an error and said "Invalid operands to binary +"
That exact thing happened to me- I had to start my entire project again () i mean the entire thing going up by 4 not one, then a few projects after, it started going up by like 56 IT'S CRAZY