我正在嘗試創建類似於Reactable的應用程序。AudioKit中對象的動態命名(SpriteKit)
用戶可以將「模塊」(如振盪器或濾波器)從菜單拖入「播放區域」,模塊將被激活。
我正在考慮初始化模塊,因爲它們與「play area」背景對象相交。然而,這需要我自動命名模塊,即:
let osci = AKOscillator()
其中OSCI會自動計數爲:
let osci1 = AKOscillator()
let osci2 = AKOscillator()
...
等
我如何能做到這一點?
感謝
編輯:我試圖通過創建
var osciArray = [AKOscillator]()
,並在我的功能陣列來使用數組來添加一個振盪器,這是我的代碼:
let oscis = AKOscillator()
osciArray.append(oscis)
osciArray[oscCounter].frequency = freqValue
osciArray[oscCounter].amplitude = 0.5
osciArray[oscCounter].start()
selectedNode.userData = ["counter": oscCounter]
oscCounter += 1
currentOutput = osciArray[oscCounter]
AudioKit.output = currentOutput
AudioKit.start()
我的應用程序構建得很好,但是一旦應用程序開始在模擬器上運行,我會收到錯誤:致命錯誤:索引超出範圍
不爲陣列或收集工作嗎? – Valdmer
我正在嘗試一個基於這個[線程]的數組(http://stackoverflow.com/questions/27716931/create-a-variable-in-swift-with-dynamic-name)。 但是,我遇到麻煩,用數組更改AKOscillator函數的參數,如 'osci.frequency = 440'等 –
什麼類型的麻煩?你不介意通過添加一些代碼來更新你的問題,你得到的錯誤,並解釋爲什麼陣列不適合你? – Valdmer