iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 横向模式在spritekit游戏中无法正常工作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我在spriteKit中开始了一个平台游戏,我对横向模式有一点问题. 当我和我的英雄一起跳跃时,我会使用 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 而当英雄它在空中并与墙壁或任何物体相撞并错过他的速度时,我就使用了 -(void)touchesMoved:(NSSet *)touches withEvent:(U
我在spriteKit中开始了一个平台游戏,我对横向模式有一点问题.
当我和我的英雄一起跳跃时,我会使用

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

而当英雄它在空中并与墙壁或任何物体相撞并错过他的速度时,我就使用了

-(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)];
}

}

保持这种速度.
我一直在纵向模式测试,一切都很好,但我的游戏是在横向模式,所以最后我已经将游戏阻挡到横向模式,现在我在横向模式下测试它,我遇到了麻烦,因为当我在跳跃中向前移动手指时,没有任何反应.而不是这个,我必须向上移动我的手指,以获得这种运动.我确定我错过了横向模式的一些基本配置.任何帮助都会被贬低

解决方法

这实际上是SpriteKit游戏中的常见问题.发生这种情况是因为viewDidLoad实际上在应用程序检查设备方向之前运行.您可以通过使用viewWillLayoutSubviews替换viewDidLoad来修复它,该视图将在检测到设备方向后运行.例如,您可以使用以下命令替换认的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 returns invalid frame?
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners

@H_502_39@

大佬总结

以上是大佬教程为你收集整理的ios – 横向模式在spritekit游戏中无法正常工作全部内容,希望文章能够帮你解决ios – 横向模式在spritekit游戏中无法正常工作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。