I got two properties initialized in header file:
@property (readwrite, assign) int Figure1;
@property (readwrite, assign) int State;
and in .m
@synthesize Figure1;
@synthesize State;
Then I got
UISwipeGestureRecognizer *swipeLeft =
[[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftMade:)] autorelease];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addGestureRecognizer:swipeLeft];
and
UITapGestureRecognizer *oneFingerTwoTaps =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ooneFingerTwoTaps)] autorelease];
[oneFingerTwoTaps setNumberOfTapsRequired:2];
[oneFingerTwoTaps setNumberOfTouchesRequired:1];
[self addGestureRecognizer:oneFingerTwoTaps];
initialized in the class.
The methods called:
- (void)ooneFingerTwoTaps
{
[NSThread detachNewThreadSelector:@selector(oneFingerTwoTaps) toTarget:self withObject:nil];
}
- (void)swipeLeftMade:(UISwipeGestureRecognizer *)recognizer
{
[NSThread detachNewThreadSelector:@selector(moveLeftSwipe) toTarget:self withObject:nil];
}
In the first thread there is the main program:
- (void)oneFingerTwoTaps
{
PlayScene *tView = [[PlayScene alloc]initWithFrame:CGRectMake(0, 0, 320, 420)];
[self addSubview:tView];
while (GameState==GamePlaying) {
Figure1 = 1; State = 1;
[self moveFig];
}
}
In the second thread I need to use the values of properties that are changed on the first thread
-(void)moveLeftSwipe {
int fset = State, figure=Figure1;
//some other stuff
}
But the problem is that the value of properties isn’t shared between threads, I was told that “nonatomic” might cause such problem, but I didn’t use it. May be I am declaring something wrong?
Just used static variables instead of properties. Static variables are shared between threads.