Thank you Paul.
Dorian, yes, you can.
First you need to replace the line graphic
constant line above with:
let graphic = Graphic(text: emojiList[note])
You'll realize this causes an error. That's because the array index needs to be an Int
, and at this point, note
isn't an Int
. We need to make sure it is. To do that, we need to redefine the note
constant like this:
let note: Int = Int(normalizedXPosition * Double(numberOfNotes - 1))
This still won't fix the problem. Now we need to say that normalizedXPosition
is a Double
. Is needs to be a Double
because, for the line above to work and give you a note between 0 and 15, normalizedXPosition
needs to be between 0 and 1, otherwise it will be either 0 or 15.
let normalizedXPosition: Double = (touch.position.x + 500) / 1000
Things should work fine now, you should have one emoji for each note.
P.S.: Before trying all the above, I did the following:
let graphic = Graphic(text: emojiList[Int(note)])
which I thought would work, because that's the usual way to cast between number types. but it didn't, so I had to go around and change all the constants. If someone else has an explanation, I'd like to learn it.