有没有办法用SpriteKit获取屏幕上所有触摸的NSSet?

时间:2014-07-22 01:13:52

标签: ios swift sprite-kit

有没有办法可以在didSimulatePhysics中找到一些内容,它可以获取当前屏幕上所有触摸的列表?

1 个答案:

答案 0 :(得分:0)

touchesBegantouchesMovedtouchesEnded中,您可以将它们分别缓存在NSMutableDictionary类属性或ivar中,然后在didSimulatePhysics中根据需要使用它们。

例如:

// in YourScene.h
NSMutableDictionary *touchCache;

// in YourScene.m
touchCache = [NSMutableDictionary dictionary];


// in your touchesBegan
[touchCache setObject:touches forKey@"touchesBegan"];


// in your touchesMoved
[touchCache setObject:touches forKey@"touchesMoved"];


// in your touchesEnded
[touchCache setObject:touches forKey@"touchesEnded"];

然后,在didSimulatePhysics中,您可以通过该ivar或类属性访问包含触摸的最后一个NSSet。

尽管如此,请记住,当触摸结束时,您应该维护这些缓存等。这只是您可以采取的方法的概念性示例。

相关问题