Reputation: 697
I'm trying to create an pause Menu when the pause button is pressed in Sprite Kit. This am i doing by creating an UIImageView. The problem is that the UIImageView is not being shown. How can i do this?
-(void)didMoveToView:(SKView *)view
{
UIButton *pauseButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[pauseButton setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
[pauseButton addTarget:self action:@selector(pausedMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:pauseButton];
}
-(void)pausedMenu:(SKView *)view
{
SKSpriteNode *menu = [SKSpriteNode spriteNodeWithImageNamed:@"pausemenu"];
//menu size is already image size (by default), no need to set it
menu.position = CGPointMake((self.size.width - menu.size.width) * 0.5,
(self.size.height - menu.size.height) * 0.5);
[self addChild:menu];
self.scene.paused = YES;
self.scene.view.paused = YES;
}
Upvotes: 2
Views: 1305
Reputation: 18997
Use SpriteKit only, why to use UIImages?
SKSpriteNode *menu = [SKSpriteNode spriteNodeWithImageNamed:@"pausemenu"];
//menu size is already image size (by default), no need to set it
menu.position = CGPointMake((self.size.width - menu.size.width) * 0.5,
(self.size.height - menu.size.height) * 0.5);
[self addChild:menu];
self.scene.paused = YES;
self.scene.view.paused = YES;
Upvotes: 4
Reputation: 12904
If you REALLY want to do this, you call put all your UIImageView stuff from,
-(void) didMoveToView:(SKView *)view {}
then when you want to call the pausedMenu items you'll have to create a new scene so that didMoveToView:
gets triggered. A scene specific to the pause menu.
Upvotes: 1