Landscape mode does not work properly in spritekit game

I started a platform game in spriteKit and I have a little problem with landscape mode. When I make a jump with my hero, I use

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

and while the hero is in the air and collides with a wall or any object and misses its speed, I use

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];

CGPoint positionInScene = [touch locationInNode:self];
SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:positionInScene];

CGPoint posicionHero = [self.world childNodeWithName:@"hero"].position;
SKSpriteNode *touchHero = (SKSpriteNode *)[self nodeAtPoint:posicionhero];

//pragma mark -hero movement in the air

if ((touchedNode != touchHero)
    &&
    (positionInScene.x > [self.world childNodeWithName:@"hero"].position.x))
{
    [[self.world childNodeWithName:@"hero"].physicsBody applyImpulse:CGVectorMake(5, 0)];
}
if ((touchedNode != touchHero)
    &&
    (positionInScene.x < [self.world childNodeWithName:@"hero"].position.x))
{
    [[self.world childNodeWithName:@"hero"].physicsBody applyImpulse:CGVectorMake(-5, 0)];
}

}

. , , , , , , , , , . , . , .

+4
1

SpriteKit. - , viewDidLoad , . , viewDidLoad viewWillLayoutSubviews, . , SpriteKit viewDidLoad :

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    if (!skView.scene) {
        skView.showsFPS = YES;
        skView.showsNodeCount = YES;

        // Create and configure the scene.
        SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;

        // Present the scene.
        [skView presentScene:scene];
    }
}

: UIViewController ? http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners

+8

All Articles