我正在尝试将值保存到精灵的用户数据中并能够将其读取.
继承人我所拥有的,由于某种原因,价值永远不会得到保存并保持为零.
import SpriteKit
let frame = SKScene()
func createSprite() {
let sprite = SKSpriteNode()
sprite.userData?.setValue("100", forKeyPath: "key")
frame.addChild(sprite)
}
createSprite()
for child in frame.children where child is SKSpriteNode {
print(child.userData?.valueForKey("key") as? String)
//prints the value saved in the childs user data
if child.userData?.valueForKey("key") as? String == "100" {
print("It was a Success!")
}
if child.userData?.valueForKey("key") as? String == nil {
print("There was a problem :(")
}
}
Run Code Online (Sandbox Code Playgroud) 我试图让输入文本字段在左上角显示文本,现在文本在中间垂直和水平居中。
<input class="userInput" type="text">
<style>
.userInput {
text-align: left;
margin: 1px;
padding: 1px;
width: 500px;
height: 300px;
vertical-align: top;
}
</style>
Run Code Online (Sandbox Code Playgroud)