[英]SpriteKit GameOverlay
If 2 objects hit each other, a GameOver layer should appear, but it should be transparent. 如果2个对象相互碰撞,则应显示GameOver图层,但该图层应该是透明的。 That means, the whole Game Scene should be showing, with a transparent GameOver and the Score etc. I can config.
这意味着应该显示整个游戏场景,并带有透明的GameOver和Score等。我可以配置。 the Scene by myself, but I don't know how to add it in my MyScene.h.
我自己创建场景,但是我不知道如何在MyScene.h中添加它。
The code for the 2 objects collision : 2个对象碰撞的代码:
- (void)didBeginContact:(SKPhysicsContact *)contact
{ SKPhysicsBody *firstBody, *secondBody; {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. 根据您的喜好调整y比例,x比例和alpha。
Another remedy: Create a image with any image editing software (gimp etc) with alpha background and add it to the scene 另一补救措施:使用任何具有alpha背景的图像编辑软件(gimp等)创建图像并将其添加到场景中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.