凉鞋学spritekit 实现单点触摸/触控

来源:互联网 发布:广州电脑锣编程培训 编辑:程序博客网 时间:2024/04/27 21:02

发现spritekit没有提供单点触控的解决方案

今天看NSObject的时候看到个hash,返回的是个NSUInteger值,就有了如下思路:

其中touchHash 是成员变量,类型为NSUInteger;
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (touchHash != 0) return;    UITouch *touch = [touches anyObject];    CGPoint rightPosition = [touch locationInNode:self];    NSLog(@"%ud",[touch hash]);    touchHash = [touch hash];}-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{    UITouch *touch = NULL;    for (UITouch *t in touches) {        if ([t hash] == touchHash) {            touch = t;        }    }    if (touch == NULL) {        return;    }    NSLog(@"%ud",[touch hash]);}-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{    UITouch *touch = NULL;    for (UITouch *t in touches) {        if ([t hash] == touchHash) {            touch = t;        }    }
    if (touch == NULL) {        return;    }
    touchHash = 0;
    NSLog(@"%ud",[touch hash]);}



0 0
原创粉丝点击