Game Development Reference
In-Depth Information
Bitmasks in Sprite Kit are 32 bit, the same as integers, and they work by setting
individual bits in an integer. Thus, there are only 32 possible masks, and you
should use them carefully, since mistakes here lead to a lot of confusion.
As bitmasks use each individual bit, you should use these numbers for masks: 1 , 2 ,
4 , 8 , 16 , 32 , and so on.
We will need to create new masks in the Common.h file and add the following code
to it:
const static int playerBitmask = 1;
const static int enemyBitmask = 2;
const static int shieldPowerupBitmask = 4;
const static int groundBitmask = 8;
We will use these bitmasks to handle different objects on screen. After this, we need
to create actual classes to handle power-ups and enemies.
Create a new ERGEnemy class and make SKNode as its parent.
We will need only one property there, that is, emitter and add it to ERGEnemy.h
using @property (strong, nonatomic) SKEmitterNode *emitter .
Now in the .m file, we will need to set up the particle emitter for the job, as follows:
- (instancetype) init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void) setup
{
self.emitter = [NSKeyedUnarchiver unarchiveObjectWithFile:
[[NSBundle mainBundle] pathForResource:@"enemy"
ofType:@"sks"]];
self.emitter.name = @"enemyEmitter";
self.emitter.zPosition = 50;
[self addChild:self.emitter];
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:20];
self.physicsBody.contactTestBitMask = playerBitmask;
self.physicsBody.categoryBitMask = enemyBitmask;
self.physicsBody.collisionBitMask = 0;
self.physicsBody.affectedByGravity = NO;
}
 
Search WWH ::




Custom Search