2016-10-02 66 views
2

我正在開發一個帶有Sprite套件的簡單飛行遊戲。一旦太空船達到最大高度和速度,它就以恆定速度飛行。我注意到太空船在不斷的飛行中隨機地出現口吃。我在這裏閱讀了關於這個問題的所有帖子,但沒有真正幫助解決它100%。Sprite套件:以恆定速度移動時的口吃

爲了測試,我寫了一個非常簡單的遊戲,其中只包含一艘太空船和一個簡單的雲(代碼如下)。但即使在這個非常簡單的遊戲中,太空飛船仍然會結結巴巴。日誌顯示,即使太空船以恆定速度飛行,太空船的移動也是隨機的,並不是恆定的。這就是口吃的原因。

希望有人能幫我解決這個問題。感謝您的任何想法。


雪碧試劑盒,目標C的Xcode 8.0,試驗裝置:iPhone 6 - 的iOS 8.3,iPhone 4S - 的iOS 9.3.5

CPU:最大21%,內存:最大8 MB,FPS:永久60 FPS


這裏我的代碼(爲簡單起見,我把所有的代碼在場景類)


FlightScene.h

#import <SpriteKit/SpriteKit.h> 

@interface FlightScene : SKScene <SKPhysicsContactDelegate> 

@end 

FlightScene.m

#import "FlightScene.h" 

#define HERO_FLIGHT_LOG 1 
//#define HERO_DEBUG_OVERLAY 1 

static const CGFloat kMaxHeroVelocityY = 100.0f; 
static const CGFloat kMaxHeroVelocityX = 200.0f; 

@implementation FlightScene 
{ 
    SKNode *_world; 
    SKSpriteNode *_hero; 
    SKSpriteNode *_cloud; 

    CGPoint _heroStartPosition; 
    CGSize _cloudSize; 
    CGFloat _xAdj; 

    BOOL _hasBegun; 

    // debug 
    CGFloat _oldHeroX; 
    CGFloat _oldHeroY; 
    int _frame; 

} 

- (void)didMoveToView:(SKView *)view 
{ 
    // Setup your scene here 

    [super didMoveToView:view]; 

    _hasBegun = NO;   
    _cloudSize = CGSizeMake(120, 80); 
    _xAdj = _cloudSize.width; 
    _heroStartPosition = CGPointMake(60, self.size.height/2); 

    [self addWorld]; 
    [self addHero]; 
    [self addCloud]; 

    // debug 
    _frame = 0; 
    _oldHeroX = 0; 
    _oldHeroY = 0; 
} 

#pragma mark - hero 

- (void)addHero 
{ 
    _hero = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship2"]; 

    _hero.size = CGSizeMake(80.0f, 70.0f); 
    _hero.position = _heroStartPosition; 
    _hero.zPosition = 1; 

    _hero.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2.0f]; 
    _hero.physicsBody.affectedByGravity = NO; 
    _hero.physicsBody.dynamic = YES; 
    _hero.physicsBody.allowsRotation = NO; 
    _hero.physicsBody.mass = 1.0f; 
    _hero.physicsBody.linearDamping = 0.0f; 
    _hero.physicsBody.friction = 0.0f; 

    [_world addChild:_hero]; 
} 

- (void)updateFlying 
{ 
    if(!_hasBegun) 
     return; 

    CGVector oldVel = _hero.physicsBody.velocity; 
    CGVector newVel = oldVel; 

    // increase the velocity 
    newVel.dx += (kMaxHeroVelocityX - newVel.dx)/10.0f; 
    newVel.dy += (kMaxHeroVelocityY - newVel.dy)/10.0f; 

    // ensure velocity doesn't exceed maximum 
    newVel.dx = newVel.dx > kMaxHeroVelocityX ? kMaxHeroVelocityX : newVel.dx; 
    newVel.dy = newVel.dy > kMaxHeroVelocityY ? kMaxHeroVelocityY : newVel.dy; 

    _hero.physicsBody.velocity = newVel; 
} 

- (void)limitHeight 
{ 
    const CGFloat maxHeight = self.size.height * 0.8f; 
    if(_hero.position.y > maxHeight) 
     _hero.position = CGPointMake(_hero.position.x, maxHeight); 
} 

- (void)updateFlight 
{ 
    // move hero with constant velocity 
    [self updateFlying]; 

    // ensure height doesn't exceed maximum 
    [self limitHeight]; 
} 

#pragma mark - game world 

- (void)addWorld 
{ 
    _world = [SKNode new]; 
    [self addChild:_world]; 
} 

- (void)addCloud 
{ 
    _cloud = [SKSpriteNode spriteNodeWithColor:[SKColor lightGrayColor] size:_cloudSize]; 

    _cloud.anchorPoint = CGPointMake(0, 1); // top left 
    _cloud.position = CGPointMake(self.size.width + _cloudSize.width, self.size.height + _cloudSize.height/2); 
    _cloud.zPosition = -1; 

    [_world addChild:_cloud]; 
} 

#pragma mark - update world 

- (void)updateCloud 
{ 
    // reposition the cloud 
    if(_world.position.x + _xAdj < -(_cloudSize.width + self.size.width)) 
    { 
     _xAdj += _cloudSize.width + self.size.width; 

     CGFloat y = arc4random_uniform(_cloudSize.height - 10); 
     _cloud.position = CGPointMake(_xAdj + self.size.width, self.size.height + y); 
    } 
} 

- (void)updateWorld 
{ 
    // move the world 
    CGFloat worldX = -(_hero.position.x - _heroStartPosition.x); 
    _world.position = CGPointMake(worldX, _world.position.y); 

    [self updateCloud]; 
    [self flightLog]; 
} 

-(void)update:(CFTimeInterval)currentTime 
{ 
    // Called before each frame is rendered 

    if(!_hasBegun) 
     return; 

    _frame++; 

    // update hero movement 
    [self updateFlight]; 
} 

- (void)didFinishUpdate 
{ 
    if(!_hasBegun) 
     return; 

    // update world movement 
    [self updateWorld];   
} 

#pragma mark - touches 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event 
{ 
    if(_hasBegun) 
     return; 

    _hasBegun = YES; 
    [self updateFlight]; 
} 


#pragma mark - debug 

- (void)flightLog 
{ 

#ifdef HERO_FLIGHT_LOG 

    CGFloat newHeroX = _hero.position.x - _heroStartPosition.x;; 
    CGFloat diffX = newHeroX - _oldHeroX; 

    CGFloat newHeroY = _hero.position.y; 
    CGFloat diffY = newHeroY - _oldHeroY; 

    NSLog(@"oldHeroY:%f, newHeroY:%f, diffY:%f", _oldHeroY, newHeroY, diffY); 
    NSLog(@"oldHeroX:%f, newHeroX:%f, diffX:%f\n\n", _oldHeroX, newHeroX, diffX); 

    if(diffX > 3.5f) 
    { 
     //NSLog(@"\t -> frame:%d fast oldHeroY:%f, newHeroY:%f, diffY:%f", _frame, _oldHeroY, newHeroY, diffY); 
     NSLog(@"\t -> frame:%d fast oldHeroX:%f, newHeroX:%f, diffX:%f\n\n", _frame, _oldHeroX, newHeroX, diffX); 
    } 
    else if(diffX < 3.0f) 
    { 
     //NSLog(@"\t -> frame:%d fast oldHeroY:%f, newHeroY:%f, diffY:%f", _frame, _oldHeroY, newHeroY, diffY); 
     NSLog(@"\t -> frame:%d slow oldHeroX:%f, newHeroX:%f, diffX:%f\n\n", _frame, _oldHeroX, newHeroX, diffX); 
    } 

    _oldHeroX = newHeroX; 
    _oldHeroY = newHeroY; 

#endif 

} 

@end 

LOG:


. 
. 
. 
// no stuttering .. FPS: 60 

2016-10-02 17:27:19.164 TestFlight[11009:1774440] oldHeroY:301.666534, newHeroY:301.666534, diffY:0.000000 
2016-10-02 17:27:19.165 TestFlight[11009:1774440] oldHeroX:263.002899, newHeroX:266.335968, diffX:3.333069 

2016-10-02 17:27:19.181 TestFlight[11009:1774440] oldHeroY:301.666534, newHeroY:301.666534, diffY:0.000000 
2016-10-02 17:27:19.182 TestFlight[11009:1774440] oldHeroX:266.335968, newHeroX:269.669067, diffX:3.333099 

// stuttering .. FPS: 60 

2016-10-02 17:27:24.584 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:302.500031, diffY:0.833344 
2016-10-02 17:27:24.585 TestFlight[11009:1774440] oldHeroX:1346.335083, newHeroX:1351.335083, diffX:5.000000 

2016-10-02 17:27:24.585 TestFlight[11009:1774440] -> frame:413 fast oldHeroX:1346.335083, newHeroX:1351.335083, diffX:5.000000 

2016-10-02 17:27:24.600 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:300.833344, diffY:-1.666687 
2016-10-02 17:27:24.601 TestFlight[11009:1774440] oldHeroX:1351.335083, newHeroX:1353.001709, diffX:1.666626 

2016-10-02 17:27:24.601 TestFlight[11009:1774440] -> frame:414 slow oldHeroX:1351.335083, newHeroX:1353.001709, diffX:1.666626 

2016-10-02 17:27:24.617 TestFlight[11009:1774440] oldHeroY:300.833344, newHeroY:301.666687, diffY:0.833344 
2016-10-02 17:27:24.618 TestFlight[11009:1774440] oldHeroX:1353.001709, newHeroX:1356.335083, diffX:3.333374 

2016-10-02 17:27:24.634 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.634 TestFlight[11009:1774440] oldHeroX:1356.335083, newHeroX:1359.668457, diffX:3.333374 

2016-10-02 17:27:24.650 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.651 TestFlight[11009:1774440] oldHeroX:1359.668457, newHeroX:1363.001831, diffX:3.333374 

2016-10-02 17:27:24.667 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:302.500031, diffY:0.833344 
2016-10-02 17:27:24.668 TestFlight[11009:1774440] oldHeroX:1363.001831, newHeroX:1368.001831, diffX:5.000000 

2016-10-02 17:27:24.668 TestFlight[11009:1774440] -> frame:418 fast oldHeroX:1363.001831, newHeroX:1368.001831, diffX:5.000000 

2016-10-02 17:27:24.684 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:300.833344, diffY:-1.666687 
2016-10-02 17:27:24.684 TestFlight[11009:1774440] oldHeroX:1368.001831, newHeroX:1369.668457, diffX:1.666626 

2016-10-02 17:27:24.685 TestFlight[11009:1774440] -> frame:419 slow oldHeroX:1368.001831, newHeroX:1369.668457, diffX:1.666626 

2016-10-02 17:27:24.700 TestFlight[11009:1774440] oldHeroY:300.833344, newHeroY:301.666687, diffY:0.833344 
2016-10-02 17:27:24.701 TestFlight[11009:1774440] oldHeroX:1369.668457, newHeroX:1373.001831, diffX:3.333374 

2016-10-02 17:27:24.717 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:302.500031, diffY:0.833344 
2016-10-02 17:27:24.718 TestFlight[11009:1774440] oldHeroX:1373.001831, newHeroX:1378.001831, diffX:5.000000 

2016-10-02 17:27:24.718 TestFlight[11009:1774440] -> frame:421 fast oldHeroX:1373.001831, newHeroX:1378.001831, diffX:5.000000 

2016-10-02 17:27:24.734 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:301.666687, diffY:-0.833344 
2016-10-02 17:27:24.734 TestFlight[11009:1774440] oldHeroX:1378.001831, newHeroX:1381.335205, diffX:3.333374 

// no stuttering .. FPS: 60 

2016-10-02 17:27:24.750 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.751 TestFlight[11009:1774440] oldHeroX:1381.335205, newHeroX:1384.668579, diffX:3.333374 

2016-10-02 17:27:24.767 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.768 TestFlight[11009:1774440] oldHeroX:1384.668579, newHeroX:1388.001953, diffX:3.333374 

2016-10-02 17:27:24.784 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.784 TestFlight[11009:1774440] oldHeroX:1388.001953, newHeroX:1391.335327, diffX:3.333374 

2016-10-02 17:27:24.801 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.801 TestFlight[11009:1774440] oldHeroX:1391.335327, newHeroX:1394.668701, diffX:3.333374 

2016-10-02 17:27:24.817 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.818 TestFlight[11009:1774440] oldHeroX:1394.668701, newHeroX:1398.002075, diffX:3.333374 

2016-10-02 17:27:24.834 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.834 TestFlight[11009:1774440] oldHeroX:1398.002075, newHeroX:1401.335449, diffX:3.333374 

2016-10-02 17:27:24.850 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.851 TestFlight[11009:1774440] oldHeroX:1401.335449, newHeroX:1404.668823, diffX:3.333374 

2016-10-02 17:27:24.867 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.868 TestFlight[11009:1774440] oldHeroX:1404.668823, newHeroX:1408.002197, diffX:3.333374 

// stuttering .. FPS: 60 

2016-10-02 17:27:24.883 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:300.833344, diffY:-0.833344 
2016-10-02 17:27:24.884 TestFlight[11009:1774440] oldHeroX:1408.002197, newHeroX:1409.668823, diffX:1.666626 

2016-10-02 17:27:24.885 TestFlight[11009:1774440] -> frame:431 slow oldHeroX:1408.002197, newHeroX:1409.668823, diffX:1.666626 

2016-10-02 17:27:24.901 TestFlight[11009:1774440] oldHeroY:300.833344, newHeroY:302.500031, diffY:1.666687 
2016-10-02 17:27:24.902 TestFlight[11009:1774440] oldHeroX:1409.668823, newHeroX:1414.668823, diffX:5.000000 

2016-10-02 17:27:24.902 TestFlight[11009:1774440] -> frame:432 fast oldHeroX:1409.668823, newHeroX:1414.668823, diffX:5.000000 

2016-10-02 17:27:24.917 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:300.833344, diffY:-1.666687 
2016-10-02 17:27:24.918 TestFlight[11009:1774440] oldHeroX:1414.668823, newHeroX:1416.335449, diffX:1.666626 

2016-10-02 17:27:24.918 TestFlight[11009:1774440] -> frame:433 slow oldHeroX:1414.668823, newHeroX:1416.335449, diffX:1.666626 

2016-10-02 17:27:24.934 TestFlight[11009:1774440] oldHeroY:300.833344, newHeroY:302.500031, diffY:1.666687 
2016-10-02 17:27:24.935 TestFlight[11009:1774440] oldHeroX:1416.335449, newHeroX:1421.335449, diffX:5.000000 

2016-10-02 17:27:24.935 TestFlight[11009:1774440] -> frame:434 fast oldHeroX:1416.335449, newHeroX:1421.335449, diffX:5.000000 

2016-10-02 17:27:24.950 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:301.666687, diffY:-0.833344 
2016-10-02 17:27:24.951 TestFlight[11009:1774440] oldHeroX:1421.335449, newHeroX:1424.668823, diffX:3.333374 

// no stuttering for a while (17 seconds .. long time) .. FPS: 60 

2016-10-02 17:27:24.967 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:24.968 TestFlight[11009:1774440] oldHeroX:1424.668823, newHeroX:1428.002197, diffX:3.333374 
. 
. 
. 

2016-10-02 17:27:41.559 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:41.559 TestFlight[11009:1774440] oldHeroX:4742.992188, newHeroX:4746.325684, diffX:3.333496 

// stuttering .. FPS: 60 

2016-10-02 17:27:41.575 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:300.833344, diffY:-0.833344 
2016-10-02 17:27:41.576 TestFlight[11009:1774440] oldHeroX:4746.325684, newHeroX:4747.992188, diffX:1.666504 

2016-10-02 17:27:41.576 TestFlight[11009:1774440] -> frame:1432 slow oldHeroX:4746.325684, newHeroX:4747.992188, diffX:1.666504 

2016-10-02 17:27:41.592 TestFlight[11009:1774440] oldHeroY:300.833344, newHeroY:302.500031, diffY:1.666687 
2016-10-02 17:27:41.593 TestFlight[11009:1774440] oldHeroX:4747.992188, newHeroX:4752.992188, diffX:5.000000 

2016-10-02 17:27:41.593 TestFlight[11009:1774440] -> frame:1433 fast oldHeroX:4747.992188, newHeroX:4752.992188, diffX:5.000000 

2016-10-02 17:27:41.609 TestFlight[11009:1774440] oldHeroY:302.500031, newHeroY:301.666687, diffY:-0.833344 
2016-10-02 17:27:41.609 TestFlight[11009:1774440] oldHeroX:4752.992188, newHeroX:4756.325684, diffX:3.333496 

2016-10-02 17:27:41.625 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:41.626 TestFlight[11009:1774440] oldHeroX:4756.325684, newHeroX:4759.659180, diffX:3.333496 

2016-10-02 17:27:41.642 TestFlight[11009:1774440] oldHeroY:301.666687, newHeroY:301.666687, diffY:0.000000 
2016-10-02 17:27:41.643 TestFlight[11009:1774440] oldHeroX:4759.659180, newHeroX:4762.992676, diffX:3.333496 
. 
. 
. 
// and so on .. 

編輯:


  • 我已將此添加到addHero:方法

    _hero.physicsBody.angularDamping = 0.0f; 
    
  • 我改變了touchesBegan:使得空間船與沒有起飛最大速度立即蒼蠅。

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event 
    { 
        if(_hasBegun) 
         return; 
    
        _hasBegun = YES; 
        _hero.physicsBody.velocity = CGVectorMake(kMaxHeroVelocityX, kMaxHeroVelocityY); 
    } 
    
    • 我運行而不updateFlying:方法的代碼。太空船立即以最大速度飛行而不起飛。它以恆定速度飛行,因此速度的更新不是必需的。

    • 我試過其他的東西,比如把更新放在didSimulatePhysics:中。打開飛行模式..作爲@Confused建議..但沒有什麼幫助解決這個問題。它仍然不是100%完美的@ crashoverride777說。

我將是任何其他的想法表示感謝。

+1

嘗試增加SKScenes didSimulatePhysics功能在你的遊戲並添加您limitHeight功能在那裏,不知道這是否會工作或沒有,但。 – DreamerNo56

+0

我做到了。看到我的編輯。不幸的是,問題仍然存在。謝謝。 – suyama

+0

我仍然在處理這個問題。蘋果只是寫回我關於這個錯誤報告,所以我給他們發送我的整個項目。當他們再次回到我身邊時,我會保持張貼。 – crashoverride777

回答

0

我會回答我自己的問題。

飛行階段:

  • 起飛
  • 一旦宇宙飛船到達最大高度和速度,它飛上 以恆定速度

問題:

  • 恆航期間太空船隨機斷續

解在這種情況下:

  • 由於恆定飛行期間發生的口吃,定義一個變量(_maxReached)來控制起飛階段的結束。

  • 一旦太空船達到最大高度和速度,設置_maxReached = YES

  • 通過更新x位置更新恆定航班(updatePosition)。

更新代碼:

. 
. 
// new: 
static const CGFloat kMaxSpeed = 5.0f; 

@implementation FlightScene 
{ 
. 
. 
. 
    // new: 
    BOOL _maxReached; 
} 

// new: rename 
//- (void)updateFlying 
- (void)takeOff 
{ 
    if(!_hasBegun) 
     return; 

    CGVector oldVel = _hero.physicsBody.velocity; 
    CGVector newVel = oldVel; 

    // increase the velocity 
    newVel.dx += (kMaxHeroVelocityX - newVel.dx)/10.0f; 
    newVel.dy += (kMaxHeroVelocityY - newVel.dy)/10.0f; 

    // ensure velocity doesn't exceed maximum 
    newVel.dx = newVel.dx > kMaxHeroVelocityX ? kMaxHeroVelocityX : newVel.dx; 
    newVel.dy = newVel.dy > kMaxHeroVelocityY ? kMaxHeroVelocityY : newVel.dy; 

    _hero.physicsBody.velocity = newVel;  
} 

- (void)limitHeight 
{ 
    const CGFloat maxHeight = self.size.height * 0.8f; 

    // new 
    if(_hero.position.y >= maxHeight) 
    { 
    if(_hero.physicsBody.velocity.dy == kMaxHeroVelocityY) 
     _maxReached = YES; 

     if(_hero.position.y > maxHeight) 
      _hero.position = CGPointMake(_hero.position.x, maxHeight); 
    } 
} 

// new: move the hero with constant velocity 
- (void)updatePosition 
{ 
    CGFloat newX = _hero.position.x + kMaxSpeed; 
    _hero.position = CGPointMake(newX, _hero.position.y); 
} 

- (void)updateFlight 
{  
    if(_maxReached) // new 
    { 
     [self updatePosition]; // move the hero with constant velocity 
    } 
    else 
    { 
     [self takeOff]; 

     // ensure height doesn't exceed maximum 
     [self limitHeight]; 
    } 
} 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event 
{ 
    if(_hasBegun) 
     return; 

    _hasBegun = YES; 
    _maxReached = NO; // new 
    [self updateFlight]; 
} 
3

這是因爲SpriteKit的默認物理和運動/變換處理沒有被修正爲/增量時間。相反,當系統調用或其他中斷導致幀速下降時,它會出現斷斷續續的情況。這些事情發生在iOS設備上很多。 iOS系統經常檢查網絡並監控各種背景活動的其他狀態,並對收到的信息作出響應。

有兩種處理方法。

  1. 打開飛行模式,關閉所有後臺更新應用程序,並嚴格限制所有應用程序在其設置中執行後臺進程;這減少了操作系統噪音和開銷。

  2. 使用增量時間滾動您自己的調整和補償機制,這樣即使跳過一幀或兩幀,事情似乎仍會以正確的速率繼續移動到預期的目的地。

+0

我試過了。即使在飛機模式仍然是問題。看到我的編輯..這似乎是精靈套件中的一個嚴重問題。當一個物體以恆定速度飛行時,沒有線性傾斜和傾斜傾斜..沒有重力..沒有摩擦..我期望在飛行過程中物體不會結結。我在想你的第二點。謝謝。 – suyama

1

我也在與我的遊戲戰鬥相同的問題。看來SpriteKit並不特別喜歡不斷的運動。

,您可以嘗試的第一件事就是用

applyForce 

,而不是直接操縱您的播放器的速度性能。

我似乎得到了最好的結果,當我在常規

override func update(_ currentTime: TimeInterval) { ... } 

方法移動玩家。

override func didFinishUpdate() { ... } 

更新相機在他們使用約束的相機蘋果樣品遊戲DemoBots。在DidSimulatePhysics之後,約束條件得到更新,因此當您手動完成時,FinFish更新似乎是最佳選擇。

還請記住,你將你的Mac當您的測試做以下的事情

1)斷開手機獲得一些性能提升。只要在插入時通過xCode運行手機,就會降低性能。

2)當您測試應用程序時,它處於調試模式,而不是處於釋放模式,這會降低性能。

要在測試轉到您的方案(您按下按鈕旁邊的按鈕來運行您的應用程序)時手動更改此項。單擊編輯方案,然後在Info中將更改構建配置更改爲Release。

請記住,您應該在完成特定測試後將其更改回來。您希望在測試應用程序時運行調試程序。

3)確保您的平局調用非常低。通過確保

ignoresSiblingOrder 

在您的GameViewController中設置爲true,這應該是默認設置。

根據它們所在的圖層,給出所有的精靈不同的z位置。

e.g

background = 1 
sun = 2 
clouds = 3 
traps, obstacles, objects = 4 
player = 5 

4),因爲它們使用的性能最少讓儘可能多的物理機構儘可能圈。

5)更新方法中儘可能少的代碼。

6)緩存紋理,特別是使用紋理動畫時。

7)如果您正在實例化它們,請將某些節點集中起來。

+0

我嘗試了更多。看到我的編輯..但不幸的是沒有什麼幫助。正如你所說,它仍然不是100%完美。我仍然在處理這個問題。如果我找到了解決方案,我會在這裏發佈。謝謝。 – suyama

+0

是的,請發佈一個解決方案,如果你找到一個,我也會如此。 – crashoverride777

+0

我有類似的問題與主要播放器的身體不適。在我的情況下,我在更新方法中設置播放器的速度,並且我更新了更新方法中的相機位置。我將更新攝像頭的位置移動到了didSimulatePhysics方法,似乎它解決了問題。 –

相關問題