我刚刚开始学习Swift,我一直在咨询Apple的Dev Guide,但在处理属性和指针时的一些语法让我失望。 Apple解释说,属性只是使用点语法,甚至API似乎反映了这一点,但它并不符合我想要的效果。这是我一直在做的事情。我也在努力实例初始化。 我已经正确创建了一个桥接标题任何指导都将不胜感激。谢谢!
这是我试图在swift中模拟的代码。
@property (nonatomic) SFWaterNode *waterSurface;
@property (nonatomic) NSTimeInterval lastUpdateTime;
@end
@implementation GameScene
- (void)didMoveToView:(SKView *)view {
self.backgroundColor = [SKColor blackColor];
CGPoint startPoint = CGPointMake(-1, self.size.height/2);
CGPoint endPoint = CGPointMake(self.size.width, self.size.height/2);
self.waterSurface = [SFWaterNode nodeWithStartPoint:startPoint endPoint:endPoint depth:self.size.height/2 color:[SKColor blueColor]];
[self addChild:self.waterSurface];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
[self.waterSurface splash:location speed:-50];
}
- (void)update:(CFTimeInterval)currentTime {
[self.waterSurface update:currentTime];
}
@end
答案 0 :(得分:2)
请尝试以下代码:
public var waterSurface:SFWaterNode?
var lastUpdateTime:NSTimeInterval
func didMoveToView(view:SKView) {
self.backgroundColor = .black
let startPoint:CGPoint = CGPoint.init(x: -1, y: self.size.height/2)
let endPoint:CGPoint = CGPoint(x: -1, y: self.size.height/2)
self.waterSurface = SFWaterNode.nodeWithStartPoint(startPoint, endPoint:endPoint, depth:self.size.height/2, color:.blue)
self.addChild(self.waterSurface)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.anyObject()
let location:CGPoint = touch.location(inNode: self)
self.waterSurface.splash(location, speed:-50)
}
func update(curentTime:CFTimeInterval) {
self.waterSurface.update(currentTime)
}