SpriteNodes停止在屏幕中间移动

时间:2014-07-21 18:27:12

标签: ios sprite-kit

我正在使用spriteKit构建游戏。

我创建了一个名为'planet'的spriteNode并设置了一个速度。它以恒定速度从屏幕顶部下降到屏幕底部。但是,它会向屏幕中间减慢并完全停止移动。我添加了方法'moveTowardPosition'作为尝试通过强制对象在屏幕外移动来解决此问题。有没有人知道问题可能是什么?

谢谢!

以下是对象的设置:

-(void)physicsBodySetup
{

//initializes the physicsBody
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:40];
self.physicsBody.affectedByGravity = NO;

//sets its category mask
self.physicsBody.categoryBitMask = TKCollisionCategoryPlanet;

//planet doesn't collide with anything
self.physicsBody.collisionBitMask = 0;

//the planet can get into contact with an astranaut
self.physicsBody.contactTestBitMask = TKCollisionCategoryAstronaut |            

}

//adds 'planet' to the screen at random position

//@param frame: the frame of the main view

-(void)addPosition:(CGRect)frame

{

//specifies a random position to add the planet on the screen
float randomPositionY = frame.size.height + self.size.height;
float randomPositionX = [TKUtil randomWithMin:10+self.size.width max:frame.size.width-10 - self.frame.size.width];
self.position = CGPointMake(randomPositionX, randomPositionY);
[self velocitySetup];
}

-(void)velocitySetup
{
//initializes the speed to be a constant
self.planetSpeed = TKPlanetSpeed;
self.physicsBody.velocity = CGVectorMake(0, self.planetSpeed);
}

//@param position: the point of planet on the screen

-(void)moveTowardsPosition:(CGPoint)position

{

float offScreenX = position.x;
float offScreenY = position.y - 2000;
CGPoint pointOffScreen = CGPointMake(offScreenX, offScreenY);

float Distance = pointOffScreen.y - position.y;
float time = Distance / self.planetSpeed;
SKAction *movePlanet = [SKAction moveTo:pointOffScreen duration:time];
NSArray *sequence = @[movePlanet, [SKAction removeFromParent]];
[self runAction:[SKAction sequence:sequence]];

}

1 个答案:

答案 0 :(得分:0)

摩擦的默认值为0.2。所以你可以尝试:

self.physicsBody.friction = 0.0

现在它不会受到表面的影响。