What is the maximum number of categoryBitMask'

2019-05-07 14:18发布

问题:

I heard only 32 different categorybitmask's are allowed to be used per Sprite Kit game. Is there any way around this? I absolutely need more then that (roughly 3-4 times more since the game is an open world one). I set up my categorybitmask's as following:

static const uint64_t boundaryCategory    = 0x1 << 0;
static const uint64_t mainCharCategory    = 0x1 << 1;
...
static const uint64_t someOtherCategory   = 0x1 << 31;

I even changed uint32_t to uint64_t hoping that would double the amount of categorybitmask's I could use. Unfortunately, it doesn't. If anyone knows any techniques to by-pass this limit, I will be very grateful.

回答1:

There are a number of ways you can get creative regarding this issue. You can, for example, use the name property of a node. Have all your enemies under one categoryBitMask and use their names to differentiate them once contact is made.

Another alternative is to use the SKNode dictionary property. This allows you to store more detailed data, if required, than just a string.

Creating a SKNode dictionary:

myNode.userData = [NSMutableDictionary dictionary];
[myNode.userData setObject:@"goblin" forKey:@"enemyType"];

Reading the dictionary:

NSString *myString = [myNode.userData objectForKey:@"enemyType"];