我在尝试确定幻灯片发生的原因。我创建了2个节点,其中一个正在使用SKAction进行移动。但是当其中一个在上面时,它不会随着它们下面的节点移动。SpriteKit SKSpriteNode slide
这是一个有点难以解释,所以我创建了视频: https://www.youtube.com/watch?v=F4OuTBVd5sM&feature=youtube_gdata_player
感谢您的答复!
零件代码:
CGPoint positionPoint = [valuePoint CGPointValue];
SKSpriteNode *slab = [SKSpriteNode spriteNodeWithTexture:plitaTexture];
slab.name = @"plita";
slab.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:plitaTexture.size];
slab.position = positionPoint;
slab.physicsBody.dynamic = NO;
CGFloat duration = 3.0;
CGFloat firstDuration = duration/(self.size.width/slab.position.x);
SKAction *moveLeftFirstTime = [SKAction moveTo:CGPointMake(0.0 + plitaTexture.size.width/2, positionPoint.y) duration:firstDuration];
SKAction *moveLeft = [SKAction moveTo:CGPointMake(0.0 + plitaTexture.size.width/2, positionPoint.y) duration:5];
SKAction *moveRight = [SKAction moveTo:CGPointMake(self.size.width - plitaTexture.size.width/2, positionPoint.y) duration:5];
SKAction *movingRightLeft = [SKAction sequence:@[moveRight, moveLeft]];
SKAction *moving = [SKAction sequence:@[moveLeftFirstTime,[SKAction repeatActionForever:movingRightLeft]]];
[slab runAction:moving];
[self addChild:slab];
兔初始化代码:
-(instancetype)init {
if (self = [super initWithImageNamed:@"eating-rabbit1"]) {
self.physicsBody = [SKPhysicsBody bodyWithTexture:self.texture size:self.texture.size];
self.physicsBody.allowsRotation = NO;
self.physicsBody.dynamic = YES;
self.physicsBody.friction = 1;
}
return self;
}
你是摇滚!非常感谢你! – Stillfinder 2014-10-13 09:02:11