我有一个非常恼人的错误,当我创建一个add child语句时,它说(作为错误): "预期声明"在addChild语句的行上 我正在使用Xcode 6和最新版本的swift
这是我的代码:
//
// GameScene.swift
// Pocket Rocket
//
// Created by Lucas Farleigh on 11/11/2014.
// Copyright (c) 2014 Lucas Farleigh. All rights reserved.
//
import SpriteKit;
class GameScene: SKScene {
let background = SKSpriteNode(imageNamed:"background")
let playButton = SKSpriteNode(imageNamed: "playbutton")
override func didMoveToView(view: SKView) {
playButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidX(self.frame))
background.yScale = 2
background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidX(self.frame)) }
self.addChild(background)
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
答案 0 :(得分:2)
您似乎在该行之前关闭了didMoveToView
方法:
override func didMoveToView(view: SKView) {
playButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidX(self.frame))
background.yScale = 2
background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidX(self.frame))
self.addChild(background)
}
错误是因为你不能在班级有表达。