我怎样才能创建一个每两秒触发一次的计时器,它会在我屏幕上的HUD上将分数增加一个?这是我对HUD的代码:
@implementation MyScene
{
int counter;
BOOL updateLabel;
SKLabelNode *counterLabel;
}
-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size])
{
counter = 0;
updateLabel = false;
counterLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
counterLabel.name = @"myCounterLabel";
counterLabel.text = @"0";
counterLabel.fontSize = 20;
counterLabel.fontColor = [SKColor yellowColor];
counterLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;
counterLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeBottom;
counterLabel.position = CGPointMake(50,50); // change x,y to location you want
counterLabel.zPosition = 900;
[self addChild: counterLabel];
}
}
Run Code Online (Sandbox Code Playgroud) 我想知道如何用spritekit创建一个墙.物体上的物体无法移动过去.我知道我可以使用这段代码:
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
...但是当我使用该代码时,我基本上也得到了"底线".我希望物体能够通过屏幕底部但不能离开侧面.
在此先感谢您的帮助!
最好的问候,路易斯.
我是如何停止并从屏幕顶部落到屏幕底部的物体弹跳.这是该对象的代码:
- (SKNode*)addRock {
SKSpriteNode* rock = [SKSpriteNode spriteNodeWithImageNamed:@"asteroid"];
rock.position=CGPointMake ([self makeRandomXWBetween:0 and:self.size.width],self.size.height);
rock.name = @"rock";
rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size];
rock.physicsBody.usesPreciseCollisionDetection = YES;
rock.physicsBody.allowsRotation = NO;
[self addChild:rock];
return self;
}
Run Code Online (Sandbox Code Playgroud)
}
在此先感谢您的帮助.
最好的问候,路易斯.