objective c - TouchesMoved only returns touches that have changed ignoring touches that haven't changed -


i'm working on simple game "particles" attracted user touches.

- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     nsarray *touch = [touches allobjects];     (numberoftouches = 0; numberoftouches < [touch count]; numberoftouches++) {         lasttouches[numberoftouches] = [((uitouch *)[touch objectatindex:numberoftouches]) locationinview:self];     }     istouching = yes; }  - (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {     nsarray *touch = [touches allobjects];     (numberoftouches = 0; numberoftouches < [touch count]; numberoftouches++) {         lasttouches[numberoftouches] = [((uitouch *)[touch objectatindex:numberoftouches]) locationinview:self];     } }  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {     nsarray *touch = [touches allobjects];     (numberoftouches = 0; numberoftouches < [touch count]; numberoftouches++) {         lasttouches[numberoftouches] = [((uitouch *)[touch objectatindex:numberoftouches]) locationinview:self];     }     if (!stickyfingers) {         istouching = no;     } } 

lasttouches array of cgpoints part of program uses move particles.

the problem having way have setup now, whenever of 3 functions called, overwrite array of cgpoints , numberoftouches. didn't think problem, turns out touchesmoved gets touches have changed , doesn't touches have stayed same. result, if move 1 of fingers not another, program forgets finger isn't moving , particles go towards moving finger. if move both fingers, particles move in between 2 fingers should.

i need someway hold on touches haven't moved while updating ones have.

any suggestions?

set theory rescue!

//instance variables nsmutableset *allthetouches; nsmutableset *touchesthathavenotmoved; nsmutableset *touchesthathavenevermoved;  //in touchesbegan:withevent: if (!allthetouches) {     allthetouches = [[nsmutableset alloc] init];     touchesthathavenotmoved = [[nsmutableset alloc] init];     touchesthathavenevermoved = [[nsmutableset alloc] init]; } [allthetouches unionset:touches]; [touchesthathavenotmoved unionset:touches]; [touchesthathavenevermoved unionset:touches];  //in touchesmoved:withevent: [touchesthathavenevermoved minusset:touches]; [touchesthathavenotmoved setset:allthetouches]; [touchesthathavenotmoved minusset:touches];  //in touchesended:withevent: [allthetouches minusset:touches]; if ([allthetouches count] == 0) {     [allthetouches release]; //omit if using arc     allthetouches = nil;     [touchesthathavenotmoved release]; //omit if using arc     touchesthathavenotmoved = nil; } [touchesthathavenotmoved minusset:touches]; [touchesthathavenevermoved minusset:touches]; 

in above, touchesthathavenotmoved hold touches didn't move in last touchesmoved:, , touchesthathavenevermoved hold touches have not moved once since began. can omit either or both variables, , statements involve them, don't care about.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -