我是Swift语言的新手,我正在使用一种使用过时的快速语言的教程。本教程是关于使用png文件创建动画。所以有6个png文件总共创建了一个动画。这是教程“https://www.youtube.com/watch?v=5aCVyrJbrHQ”的链接。我注意到旧版Swift和新版Swift之间存在重大差异。这是我被卡住的地方。
#ifndef TEST_INCLUDE_PTR
#define TEST_INCLUDE_PTR 1
template<class T>
class Ptr {
public:
T* ptr_t;
};
#endif
新版本:覆盖func touchesBegan(触摸:设置,withEvent事件:UIEvent?
旧版本:覆盖func touchesBegan(触摸:NSSet,withEvent事件:UIEvent
错误
一旦我运行模拟器并单击对象,我就没有得到任何响应,没有任何错误。我检查了我是否用对象名称输入错字但在那里什么也没找到。
这是整个文件的完整代码,以防您要求
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let shooterNode = self.childNodeWithName("shooterNode")
if(shooterNode != nil) {
let animation = SKAction.animateWithTextures(shooterAnimation, timePerFrame: 0.1)
shooterNode?.runAction(animation)
}
GameSwift.scene
import UIKit
import SpriteKit
class ShooterScene: SKScene {
var score = 0
var enemyCount = 10
var shooterAnimation = [SKTexture]()
override func didMoveToView(view: SKView) {
self.initShooterScene()
}
func initShooterScene(){
let shooterAtlas = SKTextureAtlas(named: "shooter")
for index in 1...shooterAtlas.textureNames.count {
let imgName = String(format: "shooter%01d", index)
shooterAnimation += [shooterAtlas.textureNamed(imgName)]
}
}
//Anime the shooter
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let shooterNode = self.childNodeWithName("shooterNode")
if(shooterNode != nil) {
let animation = SKAction.animateWithTextures(shooterAnimation, timePerFrame: 0.1)
shooterNode?.runAction(animation)
}
}
}
答案 0 :(得分:2)
应该是:
let shooterScene = ShooterScene(fileNamed: "ShooterScene")
而不是:
let shooterScene = SKScene(fileNamed: "ShooterScene")