Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit a564b88

Browse files
committed
workaround for SpriteKit bug #15490329 - where all but one simultaneous touches stop responding and don’t trigger touchesEnded or touchesMoved
1 parent 9180527 commit a564b88

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

SpriteKit-Components/SKComponentNode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SK_EXPORT @interface SKCTouchState : NSObject
5353

5454

5555
SK_EXPORT @interface SKComponentNode : SKNode {
56+
// workaround for SpriteKit bug #15490329
57+
NSHashTable *_touchSet;
5658
}
5759

5860
@property (nonatomic) BOOL hasEnteredScene;

SpriteKit-Components/SKComponentNode.m

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ - (id)init
6060

6161
- (void)dealloc {
6262
components = Nil;
63+
_touchSet = Nil;
6364
}
6465

6566
- (BOOL)addComponent:(id<SKComponent>)component withName:(NSString*)name {
@@ -265,7 +266,14 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
265266
_touchState.absoluteLocation= _touchState.absoluteTouchStart;
266267
_touchState.touchTime = 0;
267268
_touchState.isLongPress = NO;
268-
_touchState.isDragging = NO;
269+
_touchState.isDragging = NO;
270+
271+
// workaround for SpriteKit bug #15490329
272+
_touchSet = [NSHashTable weakObjectsHashTable];
273+
for (UITouch *touch in touches) {
274+
[_touchSet addObject:touch];
275+
}
276+
269277
}
270278
}
271279
}
@@ -312,8 +320,11 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
312320
}
313321

314322
for (UITouch *touch in touches) {
315-
if (isFingerDown && touch == _touchState.touch) {
323+
// touchSet workaround for SpriteKit bug #15490329
324+
if (isFingerDown && (touch == _touchState.touch || [_touchSet containsObject:touch])) {
325+
_touchSet = Nil;
316326
isFingerDown = NO;
327+
317328
CGPoint location = [touch locationInNode:self];
318329
CGPoint absoluteLocation = [touch locationInNode:self.scene];
319330
_touchState.touchDelta = skpSubtract(absoluteLocation, _touchState.absoluteLocation);
@@ -360,7 +371,9 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
360371
}
361372

362373
for (UITouch *touch in touches) {
363-
if (isFingerDown && touch == _touchState.touch) {
374+
// touchSet workaround for SpriteKit bug #15490329
375+
if (isFingerDown && (touch == _touchState.touch || [_touchSet containsObject:touch])) {
376+
_touchSet = Nil;
364377
isFingerDown = NO;
365378

366379
if (_touchState.isDragging) {

0 commit comments

Comments
 (0)