If 2 objects hit each other, a GameOver layer should appear, but it should be transparent. That means, the whole Game Scene should be showing, with a transparent GameOver and the Score etc. I can config. the Scene by myself, but I don't know how to add it in my MyScene.h.
The code for the 2 objects collision :
- (void)didBeginContact:(SKPhysicsContact *)contact
{ SKPhysicsBody *firstBody, *secondBody;
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask)
{
firstBody = contact.bodyA;
secondBody = contact.bodyB;
}
else
{
firstBody = contact.bodyB;
secondBody = contact.bodyA;
}
if ((firstBody.categoryBitMask & StoneCategory) != 0 &&
(secondBody.categoryBitMask & HumanCategory) != 0)
{
// Here should be some code
}
}
@interface yourScene()
@property (strong, nonatomic) SKSpriteNode *scoreMenu;
@end
...
if ((firstBody.categoryBitMask & StoneCategory) != 0 &&
(secondBody.categoryBitMask & HumanCategory) != 0)
{
self.scoreMenu = [SKSpriteNode spriteNodeWithImageNamed:@"ScoreMenuPicture.png"];
self.scoreMenu.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
self.scoreMenu.name = @"scoreMenu";
self.scoreMenu.yScale = 0.7;
self.scoreMenu.xScale = 0.5;
self.scoreMenu.alpha = 0.7;
[self addChild:self.scoreMenu];
}
adjust the y scale, x scale and alpha to your preference accordingly.
Another remedy: Create a image with any image editing software (gimp etc) with alpha background and add it to the scene
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.